Help using Base SAS procedures

Day of the Year?

Reply
New Contributor
Posts: 4

Day of the Year?

Hi!

I am very new to SAS and am using EG. I need a formula, or code, that will generate the day of the year (example; for 7/1/2010, the value 181 would be generated). Any idea how to do this?

Much thanks!
Super Contributor
Super Contributor
Posts: 3,174

Re: Day of the Year?

Here is one technique which uses INTNX function:

10 data _null_;
11 dt = '01jul2011'd;
12 x = dt - intnx('year',dt,0);
13 put x= ;
14 run;

x=181
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds



Scott Barry
SBBWorks, Inc.
New Contributor
Posts: 4

Re: Day of the Year?

I used a variation of this with the intnx function (which I never used before). Works great, thanks!
Regular Contributor
Posts: 184

Re: Day of the Year?

The JULDATE function gets you close. Use MOD to discard the year portion.

[pre]
data _null_ ;
have = '01jul2010'd ;
want = mod(juldate(have),1000) ;
put want= ;
run ;
[/pre]

> Hi!
>
> I am very new to SAS and am using EG. I need a
> formula, or code, that will generate the day of the
> year (example; for 7/1/2010, the value 181 would be
> generated). Any idea how to do this?
>
> Much thanks!
New Contributor
Posts: 4

Re: Day of the Year?

Thanks all! One follow up question, any idea how to gererate days in a given year? EG: I want the output to be 365 for most years, and 366 for leap years.
Input 2003, output 365; Input 2004, output 366.
Super Contributor
Super Contributor
Posts: 3,174

Re: Day of the Year?

Same type of SAS assignment statement, again using INTNX for both the start and end dates, however also there is the INTCK function too. Have a peek at the DOC.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

intck function site:sas.com

calculate days in year site:sas.com
Valued Guide
Posts: 2,177

Re: Day of the Year?

leap years are divisible by 4 but not 100 unless divisible by 400
Super User
Posts: 10,035

Re: Day of the Year?

[pre]

%let year=2004;
data _null_;
day=intck('day',"01jan&year"d,"01jan%eval(&year+1)"d);
put day=;
run;
[/pre]


Ksharp
Ask a Question
Discussion stats
  • 7 replies
  • 3563 views
  • 0 likes
  • 5 in conversation