1
我正在尝试使用CATS函数(组合日期,月份和年份变量)创建日期变量。 当月份,日期或年份变量丢失时,我总是收到LOG错误。将字符M/D/Y字段转换为其中可能缺少一个或多个字符的日期
的LOG看起来像这样...
NOTE: Invalid argument to function INPUT at line 41 column 12.
USUBJID=XYZ-01-002 event_seq=2 estd=31 estm=JAN esty=2013 eend=. eenm=FEB eeny=2013
EVSTDT=31-JAN-2013 EVENDT=. _ERROR_=1 _N_=3
这里是我的代码...
filename event URL "http://www.stat.wmich.edu/wang/680/data/event.csv";
RUN;
Data events;
Infile event delimiter=',' dsd firstobs=1;
Informat
USUBJID $10. event_seq 2. estd $UPCASE2.
estm $UPCASE3. esty $UPCASE4. eend $UPCASE2.
eenm $UPCASE3. eeny $UPCASE4.;
Input USUBJID event_seq estd estm esty eend eenm eeny;
If estd = "UN" then estd = '.'; If eend = "UN" then eend = '.';
If eeny = "UNK" then eeny = '.'; If esty = "UNK" then esty = '.';
If esty = " " then esty = '.'; If eeny = " " then eeny = '.';
If eend = " " then eend = '.'; If estd = " " then estd = '.';
If estm = " " then estm = '.'; If eenm = " " then eenm = '.';
Label
USUBJID = "Subject ID" event_seq = "Event Sequence"
esty = "Estimated Start Year" estd = "Estimated Start Day"
estm = "Estimated Start Month" eend = "Estimated End Day"
eenm = "Estimated End Month" eeny = "Estimated End Year";
RUN;
PROC SORT Data = events Out=ev_raw;
BY USUBJID event_seq;
RUN;
DATA event_log;
Set ev_raw;
EVSTDT = input(cat(estd, estm, esty), date9.);
EVENDT = input(cat(eend, eenm, eeny), date9.);
Format
EVSTDT EVENDT date11.;
RUN;
谢谢您的帮助!
我想要做的是分配一个缺失值“”(空白),或者至少“。”。或“NA”。我知道SAS可能会遇到这个问题,但我不得不使用字符格式?例如... EVSTDT =输入(catx(“/”,estd,estm,esty),char11。); – k6adams 2014-09-29 19:19:25
欢迎您将其存储为字符变量,但您目前没有这样做:将它输入到日期格式的数字中,该数字不能包含缺少组件值的这种概念。如果你想将它作为字符存储,只需使用'CATS'或'CATX'并且不要使用'input'(即'EVSTDT = catx('/',estd,estm,esty);'和更早的定义'EVSTDT'的长度为11)。 – Joe 2014-09-29 19:21:00
at Joe ...我的编程知识大多局限于SAS,R和LaTeX。有没有可能指引我的地方,以便我知道如何妥善发布问题?谢谢你的帮助。 – k6adams 2014-09-29 19:25:30