BookmarkSubscribeRSS Feed
Denali
Quartz | Level 8

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!

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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

novinosrin
Tourmaline | Level 20
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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1059 views
  • 0 likes
  • 2 in conversation