Hi Folks,
I have a piece of code that I use (below) to default missing days from partial dates to the first of the month when appropriate but in this case I need to default the missing days to the end of the month, which seems more complicated to a novice like me since the last day of the month can vary. Any ideas how to proceed?
/* month and year entered, default to start of month */
if substr(eoslvdat,1,1) = '-' and substr(eoslvdat,3,1) ne '-' then eoslvdtn=input(trim('01')||substr(eoslvdat,3),date9.)
data WORK.EOS;
infile datalines dsd truncover;
input _usubjid:$6. eoslvdat:$9.;
label _usubjid="Unique Subject Identifier" eoslvdat="Date of last visit";
datalines;
01/001 25APR2019
01/002 02MAY2019
01/003 08OCT2018
01/004 15NOV2018
01/005 12JUN2018
01/006 06JUN2019
01/007 --DEC2018
;;;;
Thanks for the response Reeza. In this dataset I only need to account for missing days, not months or years as I might in others. I hadn't thought of converting the -- to 01 and then using INTNX, but that seems like a good idea!
data WORK.EOS;
infile datalines dlm=' ' truncover;
input _usubjid:$6. eoslvdat :$9.;
label _usubjid="Unique Subject Identifier" eoslvdat="Date of last visit";
datalines;
01/001 25APR2019
01/002 02MAY2019
01/003 08OCT2018
01/004 15NOV2018
01/005 12JUN2018
01/006 06JUN2019
01/007 DEC2018
;;;;
data want;
set eos;
want=input(eoslvdat,?? date9.);
if want=. then want=intnx('mon',input(cats('01',eoslvdat),date9.),0,'e');
format want date9.;
run;
And suppose you have full missing values for your eoslvdat variable, the above is modified to
data want;
set eos;
if not missing(eoslvdat) then do;
want=input(eoslvdat,?? date9.);
if want=. then want=intnx('mon',input(cats('01',eoslvdat),date9.),0,'e');
end;
format want date9.;
run;
Thank you Novinosrin, this also seems like it would work, will give it a shot too!
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.