Calcite | Level 5

## 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!
7 REPLIES 7
Lapis Lazuli | Level 10

## 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.
Calcite | Level 5

## Re: Day of the Year?

I used a variation of this with the intnx function (which I never used before). Works great, thanks!
Quartz | Level 8

## 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!
Calcite | Level 5

## 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.
Lapis Lazuli | Level 10

## 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.

intck function site:sas.com

calculate days in year site:sas.com
Rhodochrosite | Level 12

## Re: Day of the Year?

leap years are divisible by 4 but not 100 unless divisible by 400
Super User

## 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
Discussion stats
• 7 replies
• 10630 views
• 0 likes
• 5 in conversation