Turn on suggestions

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

Showing results for

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

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-20-2011 12:12 PM
(1090 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

7 REPLIES 7

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

**Available on demand!**

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

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.