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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 491 views
  • 0 likes
  • 3 in conversation