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

Hi!  I need help in identifying how to assign a month and day in SAS when you only know the periods number of days in the year.  For example, in 2010, 272 days represents September 29.  I don't see any functions that would help me do that.  Does anyone have any suggestions? I am getting this data from an extract of raw data from an Oracle database.  The complete date for September 29, 2010 from the raw data is 110272.  I have figured out how to identify the year ... but can't figure out how to convert the number of days to a month and day.  Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Would need to know more about the coding scheme (or least a few more data points) but it looks like your number 110272 could be split into two pieces.  110 represents the year (add it to 1900) and 272 represents to number of days.

281  data _null_;

282     x=110272;

283     sas=mdy(1,1,1900+int(x/1000)) + mod(x,1000) -1 ;

284     diff = x - sas;

285     put x= sas= diff= sas date9.;

286  run;

x=110272 sas=18534 diff=91738 29SEP2010

View solution in original post

7 REPLIES 7
art297
Opal | Level 21

If the date is a number, you could use something like:

data want;

  format wantdate date9.;

  set have;

  wantdate=mdy(1,1,substr(put(havedate,6.),2,2))

  +substr(put(havedate,6.),4)-1;

run;

Tom
Super User Tom
Super User

Would need to know more about the coding scheme (or least a few more data points) but it looks like your number 110272 could be split into two pieces.  110 represents the year (add it to 1900) and 272 represents to number of days.

281  data _null_;

282     x=110272;

283     sas=mdy(1,1,1900+int(x/1000)) + mod(x,1000) -1 ;

284     diff = x - sas;

285     put x= sas= diff= sas date9.;

286  run;

x=110272 sas=18534 diff=91738 29SEP2010

NickR
Quartz | Level 8

data test;

          year = 2010;

          days = 272;

          date = (input('01JAN'||put(year,4.),date9.) + days) - 1;

          format date date9.;

run;

proc print; run;

Howles
Quartz | Level 8

data _null_ ;

year = 2010 ;

day_of_year = 272 ;

date = mdy(12,31,year-1) + day_of_year ;

put date = date9. ;

run ;

Luanne wrote:

Hi!  I need help in identifying how to assign a month and day in SAS when you only know the periods number of days in the year.  For example, in 2010, 272 days represents September 29.  I don't see any functions that would help me do that.  Does anyone have any suggestions? I am getting this data from an extract of raw data from an Oracle database.  The complete date for September 29, 2010 from the raw data is 110272.  I have figured out how to identify the year ... but can't figure out how to convert the number of days to a month and day.  Thanks!

Hobbes
Calcite | Level 5

I know that the question is already answered but let me just add that what you’re looking for is the conversion from a Julian Date to a SAS date and SAS has a function for that: DATEJUL

In your case, you can use, for example:


data aaa;

      x=110272;

      y=input(substr(put(x,6.),1,2)||substr(put(x,6.),4,3),5.);

      z=datejul(y);

      format z date9.;

run;

/hobbes

Peter_C
Rhodochrosite | Level 12

of course I'm too late to add much value, other than another Julian date approach

data;

   date1 = mdy(1,1,2011)-1 +272;

   put date1= date11. date1= julian.;

run;

It create these results in the Log

date1=29-SEP-2011 date1=11272

peterC

Ksharp
Super User

Hi. Peter

Long time no see.

It is good to see you again.

As Peter said, in SAS there is already  a informat to read these data.

data want;
input a $ ;
b=input(substr(a,2),julian5.);
c=put(b,yymmdd10.);
put a= b= c=;
cards;
110272
110232
;
run;








a=110272 b=18534 c=2010-09-29
a=110232 b=18494 c=2010-08-20

Ksharp

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1048 views
  • 7 likes
  • 8 in conversation