BookmarkSubscribeRSS Feed
zekez
Calcite | Level 5
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
zekez
Calcite | Level 5
I used a variation of this with the intnx function (which I never used before). Works great, thanks!
Howles
Quartz | Level 8
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!
zekez
Calcite | Level 5
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.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
Peter_C
Rhodochrosite | Level 12
leap years are divisible by 4 but not 100 unless divisible by 400
Ksharp
Super User
[pre]

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


Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 11982 views
  • 0 likes
  • 5 in conversation