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

hello,

 

I need to convert date-of-birth that is printed in text as YYYYNNN where NNN=days count from Jan1 inclusive.

 

Here are the examples:

 

Data have;

Input DOB $ ;

Datalines;

1975325

1993236

1980280

run;

 

here is the output that I would like to get:

 

DATA WANT;

FORMAT DOB $ 10.;

Input DOB $ ;

Datalines;

1975-11-21

1993-08-24

1980-06-10

RUN;

 

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't know of an informat offhand which would handle that, but just code is pretty simple:

data have;
  input dob $;
  date_of_birth=input(cats(substr(dob,1,4),"01","01"),yymmdd10.) + input(substr(dob,5),best.);
  format date_of_birth date9.; 
datalines;
1975325
1993236
1980280
run;

So create a date of 01-01-year, and then add days on.

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I don't know of an informat offhand which would handle that, but just code is pretty simple:

data have;
  input dob $;
  date_of_birth=input(cats(substr(dob,1,4),"01","01"),yymmdd10.) + input(substr(dob,5),best.);
  format date_of_birth date9.; 
datalines;
1975325
1993236
1980280
run;

So create a date of 01-01-year, and then add days on.

brulard
Pyrite | Level 9

Thanks RW9.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Actually,after scanning the formats page there is a format to do this (always best to use the informats where possible):

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201594.htm

data have;
  informat dob julian7.;
  input dob;
  format dob yymmdd10.; 
datalines;
1975325
1993236
1980280
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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