谢谢了!作者: shiyiming 时间: 2004-5-25 10:21
data jg;
set ex;/*原始数据*/
array data _numeric_;
do i=1 to 12;
date=mdy(i,1,data{1});
num=data{i+1};
output;
end;
format date monyy7.;
keep date num;
run;
其中mdy函数将月日年转为日期,我没找到仅仅转为月年的函数作者: shiyiming 时间: 2004-5-25 21:32
非常感谢GBT朋友,我先试试。作者: shiyiming 时间: 2004-5-25 22:11
Obs year jan feb mar apr may jun
ERROR: Array subscript out of range at line 62 column 5.
year=1992 jan=140,555 feb=141,037 mar=142,205 apr=142,469 may=141,139 jun=143,070 jul=146,114
aug=144,479 sep=146,259 oct=146,181 nov=146,552 dec=145,554 _I_=. i=1 date=JAN1992 num=. _ERROR_=1
_N_=1
请问是什么原因?谢谢了作者: shiyiming 时间: 2004-5-25 23:13
Plese check your EX data set to see if the variable JAN to DEC are numeric, if they are character variables, the whole thing will be screwed up.作者: shiyiming 时间: 2004-5-27 21:54
谢谢XIC,SAS中象JAN,这样的字符可以定义为数值变量吗? 怎么定义呢?不行的话,就把他改成 1 ,2, 3算了。谢谢了。作者: shiyiming 时间: 2004-5-28 08:59
Wow, it will be difficult to explain from the very beginning. I was talking about JAN to DEC as variable names, not the values. The value of 1, 2, 3 can also be characters, and the value as JAN, FEB and so on can also be numeric if you attach a format on it. I would like you to check the variables JAN to DEC to see if they are character variables. If they are, the program posted by GBT may need a minor modification.作者: shiyiming 时间: 2004-5-28 09:21
data ex;
input year jan$8. feb$8. mar$8. apr$8. may$8. jun$8. jul$8. aug$8. sep$8. oct$8. nov$8. dec$8. ;
dec$ ;
cards;
1992 140,555 141,037 142,205 142,469 141,139 143,070 146,114 144,479 146,259 146,181 146,552 145,554
1993 150,578 149,325 146,865 150,091 152,720 149,890 151,342 151,798 152,033 152,549 152,560 149,960
1994 153,649 154,307 157,063 156,658 157,825 159,359 160,764 165,445 164,606 167,360 167,970 170,352
1995 171,989 173,509 171,765 174,247 174,973 176,509 176,413 177,577 178,342 179,075 181,040 183,607
1996 180,514 181,534 183,910 183,751 184,293 185,330 186,883 188,271 188,101 189,382 190,788 188,783
1997 190,891 195,484 194,038 192,815 194,107 194,091 194,118 194,000 196,804 195,953 196,059 195,203
1998 197,373 197,332 198,588 198,442 198,398 197,191 198,259 197,049 197,780 199,016 199,066 200,492
1999 200,092 202,494 204,619 205,573 210,072 211,370 212,417 214,001 215,417 218,591 220,626 222,130
2000 224,266 223,581 226,181 227,475 227,656 230,653 229,532 229,118 231,415 232,197 230,377 233,327
2001 231,919 231,106 227,998 226,514 227,599 223,126 224,580 224,778 224,550 219,797 220,125 219,506
2002 221,219 223,009 223,315 226,696 227,493 228,840 229,345 232,391 231,790 231,287 233,819 232,033
2003 235,248 235,557 237,727 234,998 234,073 237,209 239,113 240,029 241,527 246,430 247,737 251,526
2004 253,664 259,109 266,213
;
data jg;
set ex;
array y _numeric_ ;
array data _character_;
do i=1 to 12;
date=mdy(i,1,y{1});
num=data{i};
output;
end;
format date monyy7.;
keep date num;
run;