Hi,
I have a column contain year information and another column contains month information. I would like to combine these two columns into one.
ID YEAR MONTH Date (this is what I want)
001 2012 08 08/2012
002 2000 10 10/2000
003 06 06/0000
004 2010 99 00/2010
005 2009 88 00/2009
I used below code:
Date = mdy(Month,1,Year);
format Date mmyys7.;
It worked well when both columns contain information. However, it will show missing if someone only has either year or month data. Is there a way to keep the information as mush as possible?
Note: "blank", "88" or "99" are "missing". In the Date variable, I simply wrote "00" represents those do not have month info and "0000" for those without year info. Does anyone has better way to keep the missing info in the "Date" variable?
Thanks in advance!
is it ok to have to date(want) as character var rather than numeric sas date for the reason you have data integrity issues? If yes, it;s a simple if then and catx
data have;
input ID YEAR MONTH ;
cards;
001 2012 08 08/2012
002 2000 10 10/2000
003 . 06 06/0000
004 2010 99 00/2010
005 2009 88 00/2009
;
data want;
set have;
length want $7;
if missing(year) then year=0;
if not (1<=month<=12) then month=0;
want=catx('/',put(month,z2.),put(year,z4.));
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.