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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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