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.
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;
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;
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;
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.
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.