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
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.
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;
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.
Thanks for your response. As you guessed, I had the aggregation set to sum. Changed it to minimum and it calculates as expected.
data _null_;
DayOfYear=put(date(),julday.);
put DayOfYear=;
run;
Thank you to everybody that replied. The problem was that I had aggregation set to 'Sum'. When set to 'Minimum' it calculates as expected.
Please update your post as answered in that case.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.