Hi all,
I have a dataset with a variable birthday saved as text type (bithday_old) and I want to convert it to bithday_new using 15 of the month and make it as number type so that I can calculate the age
| bithday_old | bithday_new |
| 1947/02 | 1947-02-15 |
| 1970/06 | 1970-06-15 |
| 1953/08 | 1953-08-15 |
| 1940/12 | 1940-12-15 |
| 1930/01 | 1930-01-15 |
| 1961/02 | 1961-02-15 |
| 1964/02 | 1964-02-15 |
| 1964/12 | 1964-12-15 |
Thank you fo ryour help as always
data have;
input bithday_old $;
datalines;
1947/02
1970/06
1953/08
1940/12
1930/01
1961/02
1964/02
1964/12
;
data want(drop=month year);
set have;
month=input(scan(bithday_old, 2, '/'), 8.);
year=input(scan(bithday_old, 1, '/'), 8.);
bithday_new=mdy(month, 15, year);
format bithday_new yymmdd10.;
run;
data have;
input bithday_old $;
datalines;
1947/02
1970/06
1953/08
1940/12
1930/01
1961/02
1964/02
1964/12
;
data want(drop=month year);
set have;
month=input(scan(bithday_old, 2, '/'), 8.);
year=input(scan(bithday_old, 1, '/'), 8.);
bithday_new=mdy(month, 15, year);
format bithday_new yymmdd10.;
run;
Hi,
You can use the code below:
data check_new;
set check;
date = input(birthday_old||'/'||'15',yymmdd10.);
birthday_new= intnx('month',date,0,'s');
format date birthday_new yymmdd10.;
drop date;
run;
Output would be :
birthday_old birthday_new
| 1947/02 | 1947-02-15 |
| 1970/06 | 1970-06-15 |
| 1953/08 | 1953-08-15 |
| 1940/12 | 1940-12-15 |
| 1930/01 | 1930-01-15 |
| 1961/02 | 1961-02-15 |
| 1964/02 | 1964-02-15 |
| 1964/12 | 1964-12-15 |
I hope it helps!
Regards,
Anushree
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.