Sas 将字符M/D/Y字段转换为可能缺少一个或多个字段的日期

Sas 将字符M/D/Y字段转换为可能缺少一个或多个字段的日期,sas,Sas,我正在尝试使用CATS函数创建一个日期变量(组合日、月和年变量)。 当月、日或年变量丢失时,我会不断收到日志错误 日志看起来像这样 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

我正在尝试使用CATS函数创建一个日期变量(组合日、月和年变量)。 当月、日或年变量丢失时,我会不断收到日志错误

日志看起来像这样

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;

谢谢你的帮助

当您输入缺少月、日或年的日期时,您希望得到什么?如果我告诉你日期是“2001年1月”,你必须指向日历上的一个特定的正方形,你指的是哪个正方形

你需要一些代码来处理这个问题。有时,您可能会在忽略日期时选择默认的日期=1,在忽略月份时选择默认的月份=1(强制日期=1,因为它不太具体)。如果不考虑年份,我不知道除了将整个日期设置为missing之外您会做什么,除非年份在您的特定用例中不是很重要。其他人可能会将日期默认为15,或将月份默认为6或7(因为这是可能值的平均值)。如果缺少任何组件,其他人只需将日期设置为missing


你选择做什么取决于你的数据和你的需求,但你必须给SAS一些东西来处理;它不会为您做出决定。

我想做的是分配一个缺少的值“”(空白),或者至少是“.”或“NA”。我知道SAS可能对此有异议,但我是否被迫使用字符格式?例如EVSTDT=输入(catx(“/”,estd,estm,esty),字符11);欢迎您将其存储为字符变量,但您当前没有这样做:您正在将其输入到一个日期格式的数字中,该数字不能有缺少组件值的概念。如果您想将其存储为字符,只需使用
CATS
CATX
,不要使用
input
(即,
EVSTDT=CATX('/',estd,estm,esty);
和更早的版本将
EVSTDT
的长度定义为11)。。。我的编程知识主要局限于SAS、R和LaTeX。是否有任何地方可以让我知道如何恰当地发布问题?谢谢你的帮助。你的问题没有问题,尽管你包含了比必要的更多的代码——如果你只给出一个简短的例子,其中包含了你感兴趣的有限部分,那么就更容易了,尽管在这种情况下,它并没有那么多。