s********1 发帖数: 54 | 1 Compare data inf123 and data inf, who can explain to me why outputs from
these two codes are not the same? Data inf is the right one. In terms of the
difference, they are represented as follows:
In data inf123
length readd $10.;/*先把長度都開好*/
input group id_n name $ job $12. st_time $10.;
In data inf
length job $12 readd $10 st_time $10;/*先把長度都開好*/
input group id_n name $ job $ st_time $;
______________________________________________
data inf123 ;
length readd $10.;/*先把長度都開好*/
input group id_n name $ job $12. st_time $10.;
if group=1 then readd='date9.';/*如果group值是1,就在readd變項裡面
放對應的date9.*/
else readd='mmddyy10.';/*反之就給mmddyy10.,請注意這裡不是隨便給格
式,是要考慮原始資料樣貌*/
newd=INPUTN(st_time, readd);/*前面放要改的變項名稱,後面就放我自訂的readd
變項(裡面已經coding好格式的文字)*/
cards;
1 1234 Zork lawer 10AUG2001
1 4567 Penny Star 23SEP1985
2 9512 Sheldon Scientist 10/06/1999
2 3575 Raj Scientist 08/08/1986
;
run;
proc print;run;
______________________________________________
data inf ;
length job $12 readd $10 st_time $10;/*先把長度都開好*/
input group id_n name $ job $ st_time $;
if group=1 then readd=’date9. ‘;/*如果group值是1,就在readd變項
裡面放對應的date9.*/
else readd=’mmddyy10.’;/*反之就給mmddyy10.,請注意這裡不是隨便給
格式,是要考慮原始資料樣貌*/
newd=INPUTN(st_time, readd);/*前面放要改的變項名稱,後面就放我自訂的readd
變項(裡面已經coding好格式的文字)*/
cards;
1 1234 Zork lawer 10AUG2001
1 4567 Penny Star 23SEP1985
2 9512 Sheldon Scientist 10/06/1999
2 3575 Raj Scientist 08/08/1986
;
run;
proc print;run;
________________________________________________________
Output from data inf
________________________________________________________
Obs job readd st_time group id_n name newd
1 lawer date9. 10AUG2001 1 1234 Zork 15197
2 Star date9. 23SEP1985 1 4567 Penny 9397
3 Scientist mmddyy10. 10/06/1999 2 9512 Sheldon 14523
4 Scientist mmddyy10. 08/08/1986 2 3575 Raj 9716
________________________________________________________
Output from data inf123
________________________________________________________
Obs readd group id_n name job st_time newd
1 date9. 1 1234 Zork lawer 10A UG2001 .
2 date9. 1 4567 Penny Star 23SE P1985 .
3 mmddyy10. 2 9512 Sheldon Scientist 10 /06/1999 .
4 mmddyy10. 2 3575 Raj Scientis t 08/08/19 . |
|