BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Bubson
Fluorite | Level 6

I am getting a nonsense value for:

 

DayOfYear(TreatAs(_Date_, DatePart(Now())))

 

The result I get is 31,501,320

Should be 40.

 

Anybody no what I am doing wrong.

 

Many thanks in advance.

 

Tim

1 ACCEPTED SOLUTION

Accepted Solutions
Nigel_Pain
Lapis Lazuli | Level 10

If you check the properties of your calculated item you'll probably find that the Aggregation is set to "Sum", so that it's effectively multiplying the number of days in the year by the number of records. in the table. Change it to "Average", "Minimum" or "Maximum" and it should display the correct value.

View solution in original post

6 REPLIES 6
MayurJadhav
Quartz | Level 8

There are couple of ways you can achieve this.

Here is the simplest one:

 

Example 1: Simple and straightforward

You can remove +1 if you don't want to count todays date.

 

data _null_;
nrOfDays=intck('day', '01JAN2023'd, today()) + 1;
put nrOfDays=;
run;

 

Example 2: Dynamic start date

In case if you don't want to hard code date 01JAN2023 then you can use following code:

 

data _null_;
	format beginning date9.;
	beginning=intnx('year ', today() , 0, 'b');
	nrOfDays=intck('day', beginning, today()) + 1;
	put beginning=;
	put nrOfDays=;
run;
Mayur Jadhav
BI Developer. Writer. Creative Educator.

SAS Blog → https://learnsascode.com
YouTube Channel: → https://www.youtube.com/@imayurj
Nigel_Pain
Lapis Lazuli | Level 10

If you check the properties of your calculated item you'll probably find that the Aggregation is set to "Sum", so that it's effectively multiplying the number of days in the year by the number of records. in the table. Change it to "Average", "Minimum" or "Maximum" and it should display the correct value.

Bubson
Fluorite | Level 6

Thanks for your response. As you guessed, I had the aggregation set to sum. Changed it to minimum and it calculates as expected.

Ksharp
Super User
data _null_;
DayOfYear=put(date(),julday.);
put DayOfYear=;
run;
Bubson
Fluorite | Level 6

Thank you to everybody that replied. The problem was that I had aggregation set to 'Sum'. When set to 'Minimum' it calculates as expected.

SASKiwi
PROC Star

Please update your post as answered in that case.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 626 views
  • 0 likes
  • 5 in conversation