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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 2 replies
  • 503 views
  • 0 likes
  • 3 in conversation