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
;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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