BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasworker16
Calcite | Level 5

Hello,

 

I have a dataset where people's birth years and months are recorded.

I want to assume that each person was born on the first date of each month.

 

e.g) Someone born in April of 1980->April 1st, 1980 

 

data one; 
input ID $ birth_ym;
cards;
1 198004 
2 199712 
3 200207
;
run;

I would want to create a variable that has '01' added to the end for each value of birth_ym

 

198004->19800401

199712->19971201

200207->20020701

 

So, I would want a variable to include

 

birthday_new

19800401

19971201

20020701

 

Is there a simple way to solve this problem?

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
msjpnw
Calcite | Level 5

Can you read the existing month/year date value as a character string? If so, then this will work:

 

data one (keep=ID birthday_new);
length ID $7 birth_ym $6;
input ID $ birth_ym $;
birthday_new = input( birth_ym || '01',  yymmdd8.);
format birthday_new date10.;
cards;
1 198004
2 199712
3 200207
;
run;

 

 

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Do you mean you are looking for 

   

 

YYMMNw. Informat



Reads date values in the form yyyymm or yymm.

 

data one; 
input ID $ birth_ym : yymmn6.;
format 	birth_ym date9.;
cards;
1 198004 
2 199712 
3 200207
;
run;
msjpnw
Calcite | Level 5

Can you read the existing month/year date value as a character string? If so, then this will work:

 

data one (keep=ID birthday_new);
length ID $7 birth_ym $6;
input ID $ birth_ym $;
birthday_new = input( birth_ym || '01',  yymmdd8.);
format birthday_new date10.;
cards;
1 198004
2 199712
3 200207
;
run;

 

 

Astounding
PROC Star

You should study how SAS stores dates.  Dates are much more useful when stored in the form that SAS expects.  These are numeric variables, not dates.

 

That being said, converting y our numbers to different numbers is relatively straightforward:

 

birthdate = birth_ym * 100 + 1;

 

If you wanted to convert these values to the form that SAS expects, you could add after this equation:

 

birthdate = input(put(birthdate, z8.), yymmd8.);

format birthdate yymmdd10.;

 

But dates in the "correct" form may not be useful to  you until you understand what they contain.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 513 views
  • 0 likes
  • 4 in conversation