SAS中資料輸入和輸出的幾種方式

2021-08-31 13:45:27 字數 2106 閱讀 6766

sas中資料輸入和輸出的方式有:

1.按列輸入: input 變數名 <$> 《起始位置》 <-結束位置》

data score; /*建立關於成績的資料集*/

input name $ 1-10 math 11-12 chinese 17-18 english 26-27; /*對每個變數,按列輸入資料*/

datalines; /*提示下面是資料行*/

bital     90    92       88

martin    80    95       94

run;

2.列表輸入: input 變數名 <$> 《輸入格式》 <@|@@>

data; /*資料集名稱預設,預設為data1*/

length city $ 9 /*指定字元型變數的長度為9(預設為8個位元組,超長會被截斷)*/;

input city $ sales /*列表輸入變數: city、sales*/; 

cards;  /*提示下面是資料行, 與datalines等價*/

shenzhen 8000

guangdong 5000

shanghai 10000

beijing 12000

run;

3.格式化輸入:

data;

input id 4. @9 name $15. @25 *** $1. @31 age 2. @38 salary comma6.; /*採用格式輸入*/

cards;

2458    murray,w        m     27     11,579

2459    almers,c        f     34     13,640

2460    johonson,r      m     38     22,713

run;

4.資料輸出

輸出到sas視窗:    file 標識名     《選項 log|print>

輸出到外部檔案:   file '檔案路徑' 《選項》;

data price;

format date yymmdd10.;               /*設定變數date輸出格式為日期輸出格式:yymmdd10.*/

format city $2.;                             /*設定變數city的字元輸出格式為:$2.*/

format price1 6.2;                        /*設定變數price1的數值輸出格式為:6.2*/

format price2 6.2;                        /*設定變數price2的數值輸出格式為:6.2*/ 

format price3 7.2;                        /*設定變數price3的數值輸出格式為:7.2*/ 

informat date date9.;                    /*設定變數date輸入格式為日期輸出格式:date9.*/

informat city $2.;                          /*設定變數city的字元輸入格式為:$2.*/

informat price1 12.8;                    /*設定變數price1的數值輸入格式為:12.8*/

informat price2 12.8;                    /*設定變數price2的數值輸入格式為:12.8*/ 

informat price3 12.7;                    /*設定變數price3的數值輸入格式為:12.7*/

input date city $ price1 price2 price3;  /*採用列表輸入*/

cards;

11jan2017 sz 721.91999912 138.80999994 2434.3699999

28feb2017 sh 715.19999981 137.73999995 2410.6399994

05mar2017 gz 708.58999943 150.13       2455.0099993

;run;

proc print data=price;

run;

資料的輸入和輸出

如果函式scanf 的格式控制字串中存在除格式說明外的其它字元,那麼這些字元必須在輸入資料時有使用者從鍵盤原樣輸入,例如 輸入資料之間以空格作為分隔符,scanf d d a,b 輸入資料之間以逗號作為分隔符,scanf d,d a,b 輸入資料之間以回車符作為分隔,scanf d d a,b 在用...

overlay中的輸入和輸出

overlay技術跟幀快取技術都可以用於顯示。overlay在驅動層是v4l2架構。struct v4l2 format format format.type v4l2 buf type video output ret ioctl fd,vidioc g fmt,format,get format...

Shell中的輸入和輸出

終端使用者登入linux伺服器,為每乙個終端使用者啟動乙個shell程式。echo 空,後面沒有任何東西,將要有乙個回車換行 示例 bin bash echo don t anylisize special charaters.echo demo n n n echo anylisize speci...