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

Have a date field on INFILE with format CCYY.JJJ and need to convert to SAS date. Can't seem to wrap my head around this for some reason. Example of input date:

2020.350

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Remove the period and use JULIAN7. informat.  Or parse out the YEAR and DAYS part and re-combine them.

data test;
  input str $ ;
  date1=input(compress(str,'.'),julian7.);
  date2=mdy(1,1,input(str,4.))+input(scan(str,2,'.'),3.)-1;
  format date: yymmdd10.;
  put (_all_) (=);
cards;
2020.350
2020.001
;

View solution in original post

4 REPLIES 4
Reeza
Super User

What should that map to? Is 350 the # of days? ie roughly December 15/16, 2020?

If so, I think that's a Julian Date.
https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=leforinforref&docsetTarge...

data test; 
date='2018099'; 
sasdate=input(date,julian7.); 
put sasdate ; 
put sasdate date9.; 
run;

@G_I_Jeff wrote:

Have a date field on INFILE with format CCYY.JJJ and need to convert to SAS date. Can't seem to wrap my head around this for some reason. Example of input date:

2020.350




G_I_Jeff
Obsidian | Level 7
Reeza,
It is a Julian date, but the field has the full year (CCYY) separated with the Julian date (JJJ) with a period:

2020.350
How do you take account of the period in the INPUT statement?

Jeff
Reeza
Super User
Remove the period (COMPRESS) or create a custom informat that handles the period. I'd lean towards the COMPRESS option.
Tom
Super User Tom
Super User

Remove the period and use JULIAN7. informat.  Or parse out the YEAR and DAYS part and re-combine them.

data test;
  input str $ ;
  date1=input(compress(str,'.'),julian7.);
  date2=mdy(1,1,input(str,4.))+input(scan(str,2,'.'),3.)-1;
  format date: yymmdd10.;
  put (_all_) (=);
cards;
2020.350
2020.001
;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 706 views
  • 7 likes
  • 3 in conversation