Well well, Have i not understood your question clearly or could you explain better please. Are you trying to extract date from the top 5 obs in your sample and then add or minus with other dates?It's difficult to understand what you are trying to achieve. Please provide your sample(have) dataset and (want) dataset.
I have
So if you have 2003 what date do you want to map that to?
Same for 2007/2008?
And if you have month & year what are you assuming the day is? Can you assume the first, last or should you assume middle of the month?
For anyday within a month
You are still way to vague.
Show exactly what kind of output you desire based on input data, and try to explain in more words why/how.
If first day of the month is OK, try this code. Jim
data;
input dat $20.;
len=length(dat); monyr=' ';
if len=4 then do;
ndat=input(dat,4.);
date=mdy(1,1,ndat);
end;
if len=8 then date=input(dat,monyy10.);
if len gt 8 then do;
mon=scan(dat,1); day=scan(dat,2); yr=scan(dat,3);
*monyr=mon||yr;
substr(monyr,1,3)=mon; substr(monyr,4,4)=yr;
date=input(monyr,monyy10.);
nday=input(day,2.); date=date+nday-1;
end;
format date mmddyy10.;
cards;
2003
2007
2008
AUG-2009
AUG-2003
SEP-12-2009
proc print; run;
In clinical trials data processing there is "always" a document that provides information on how incomplete dates (or anything else) should be imputed. You should read that.
Perhaps something like this.
01-JUL-year when you have only the year.
15-mon-year when you have only month and year.
Sometimes the imputation is slightly different if the date is a start versus an end date.
The point is, the answer to the imputation is in the documentation for the analysis and you already have that.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.