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

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_oldbithday_new
1947/021947-02-15
1970/061970-06-15
1953/081953-08-15
1940/121940-12-15
1930/011930-01-15
1961/021961-02-15
1964/021964-02-15
1964/121964-12-15

 

Thank you fo ryour help as always

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
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;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
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;
anushreebiotech
Obsidian | Level 7

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/021947-02-15
1970/061970-06-15
1953/081953-08-15
1940/121940-12-15
1930/011930-01-15
1961/021961-02-15
1964/021964-02-15
1964/121964-12-15

 

I hope it helps!

 

Regards,

Anushree

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 738 views
  • 0 likes
  • 3 in conversation