turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- How do you assign a month and day in SAS when you ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 12:12 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 12:26 PM

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

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 12:22 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 12:26 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 12:41 PM

data test;

year = 2010;

days = 272;

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

format date date9.;

run;

proc print; run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 12:45 PM

**data** _null_ ;

year = **2010** ;

day_of_year = **272** ;

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

put date = date9. ;

**run** ;

Luanne wrote:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 03:19 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-20-2011 05:42 PM

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

**data**;

put date1= date11. date1= julian.;

**run**;

It create these results in the Log

**date1=29-SEP-2011 date1=11272**

peterC

** **

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-21-2011 03:08 AM

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