Hello guys,
I have a dataset with some variables of which one is the date.
My problem is that I want to create a subset with a certain period between dates.
The program should take a given date minus a number of previous observations.
Like I have 30. Mar 2001 and I want to create the subset with the observations: 30. Mar 2001 - 260 observations till 30. Mar 2001 - 11 observations.
I tried to set the period with
where date between '30mar2001'd-260 and '30mar2001'd-11;
but this will only work if there is a observation for every date.
SAS 9.4
Hope you can help.
Thanks a lot!
Regards,
Pascal
Please provide example data (in a data step with datalines, see my footnotes), and what the result from that should be.
While your question is not particularly clear, here is an approach you can tailor to your needs.
proc sort data=have out=subset;
by descending date;
where date <= '30mar2001'd;
run;
data want;
set subset;
**** Now you can add your own logic here that depends on the date and/or
_N_ which will number the observations beginning with March 30 having _N_=1. ;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.