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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.