Help using Base SAS procedures

How do you assign a month and day in SAS when you only know the current days in year

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

How do you assign a month and day in SAS when you only know the current days in year

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!


Accepted Solutions
Solution
‎09-20-2011 12:26 PM
Super User
Super User
Posts: 6,498

How do you assign a month and day in SAS when you only know the current days in year

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


All Replies
PROC Star
Posts: 7,360

How do you assign a month and day in SAS when you only know the current days in year

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;

Solution
‎09-20-2011 12:26 PM
Super User
Super User
Posts: 6,498

How do you assign a month and day in SAS when you only know the current days in year

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

Frequent Contributor
Posts: 81

How do you assign a month and day in SAS when you only know the current days in year

data test;

          year = 2010;

          days = 272;

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

          format date date9.;

run;

proc print; run;

Regular Contributor
Posts: 184

How do you assign a month and day in SAS when you only know the current days in year

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!

Occasional Contributor
Posts: 16

Re: How do you assign a month and day in SAS when you only know the current days in year

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

Valued Guide
Posts: 2,174

Re: How do you assign a month and day in SAS when you only know the current days in year

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

Super User
Posts: 9,671

Re: How do you assign a month and day in SAS when you only know the current days in year

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 163 views
  • 7 likes
  • 8 in conversation