BookmarkSubscribeRSS Feed
Pascal1
Calcite | Level 5

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

2 REPLIES 2
Astounding
PROC Star

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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
  • 2 replies
  • 583 views
  • 0 likes
  • 3 in conversation