Datdif Function in a given time period

Reply
Contributor
Posts: 47

Datdif Function in a given time period

Hello

This is my first time posting a discussion and I am hoping someone can help me out.

I am trying to use the Datdif function to calculate the value of a variable in a given time periode. I want to calculate the value of the variable "performance"  for the last 365 days.

I want to include the value of the variable between the start date and the end date. So I can see how someone has performed for the last year.

I am using the Proc Report data function. The relevant code looks like the following:

DEFINE OBS / GROUP NOPRINT;

DEFINE ParentNodeName/ 'Type' GROUP;

DEFINE ModelPortfolioName / 'Class' GROUP STYLE(column) = [cellwidth=/*150pt*/130pt] ORDER=DATA;;

DEFINE Performance / 'Performance ' FORMAT=COMMAX20.1 STYLE(column) = [cellwidth=/*50pt*/40pt] style(column) = {font_weight=Bold foreground=cback.};

WHERE DATDIF(mdy(12, 31, 2009), &ReportDate, 'act/act')>-365 AND ParentNodeName in ('A', 'B', 'C');

Run;


When I run the above code the value of variable does not change when i type -365 og -10 days. I keep getting the same value.

Can someone help me?


Thanks

Super User
Posts: 17,784

Re: Datdif Function in a given time period

What does &reportDate look like, is it a valid sas date?

If they're both dates you can use straight subtraction instead, and I'm sure you realize 365 will fail for leap years.

I also don't know what you mean by the "value of variable does not change", you're only limiting the selection for the report. 

Contributor
Posts: 47

Re: Datdif Function in a given time period

Hello

Yes, &reportdate is valid. It is written so my program will keep taking the newest file/input data.

What I meant by "same value" was that even though i change the constraint for how many days the program should go back in the time it still gives the be the same value/answer - fx it keeps saying that the performance is 10 even though i change the number of days it should go back in time from 50 to 200.

If i wish to add, how do i add the values of the same variable for the previous 365 days?

I am quite new in the sas coding department, so I have some problems here

Your help will be greatly appreciated.

Thanks

Respected Advisor
Posts: 4,644

Re: Datdif Function in a given time period

Chances are that reportDate is the result of something like

%let reportDate=%sysfunc(today(),date9.);

in which case your condition should read:

DATDIF(mdy(12, 31, 2009), "&ReportDate"d, 'act/act')>-365

note the use of double quotes.

PG

PG
Contributor
Posts: 47

Re: Datdif Function in a given time period

Hello

Yes, that is correct.

I have not tried that, since I used the statement "&ReportDate" earlier in the program without any program, but I will try your suggestion.

Thanks.

Ask a Question
Discussion stats
  • 4 replies
  • 188 views
  • 6 likes
  • 3 in conversation