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

Please help me with selecting record from a certain date range. The variable is Comp_Date (formatted already as a date) and I want to select (e.g. 20, 30...) records to view all with all of the other variables.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Using sashelp.Stocks as an example as no data is provided:

 

data stocks;
set sashelp.stocks (obs=30 where =( '01Jan1990'd <= date <= '31Dec1995'd));
run;

Log:

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         data stocks;
 70         set sashelp.stocks (obs=30 where =( '01Jan1990'd <= date <= '31Dec1995'd));
 71         run;
 
 NOTE: There were 30 observations read from the data set SASHELP.STOCKS.
       WHERE (date>='01JAN1990'D and date<='31DEC1995'D);
 NOTE: The data set WORK.STOCKS has 30 observations and 8 variables.

@Jallah_Kennedy wrote:

Please help me with selecting record from a certain date range. The variable is Comp_Date (formatted already as a date) and I want to select (e.g. 20, 30...) records to view all with all of the other variables.

Thanks.



 

View solution in original post

3 REPLIES 3
ballardw
Super User

20 or 30 is not a "date range". A date range would typically refer to a start date value and and end date value. Is that what you want?

If so, what range specifically do you want?

Reeza
Super User

Using sashelp.Stocks as an example as no data is provided:

 

data stocks;
set sashelp.stocks (obs=30 where =( '01Jan1990'd <= date <= '31Dec1995'd));
run;

Log:

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         data stocks;
 70         set sashelp.stocks (obs=30 where =( '01Jan1990'd <= date <= '31Dec1995'd));
 71         run;
 
 NOTE: There were 30 observations read from the data set SASHELP.STOCKS.
       WHERE (date>='01JAN1990'D and date<='31DEC1995'D);
 NOTE: The data set WORK.STOCKS has 30 observations and 8 variables.

@Jallah_Kennedy wrote:

Please help me with selecting record from a certain date range. The variable is Comp_Date (formatted already as a date) and I want to select (e.g. 20, 30...) records to view all with all of the other variables.

Thanks.



 

Jallah_Kennedy
Fluorite | Level 6

Thanks you so much. It worked. Much appreciated.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 850 views
  • 2 likes
  • 3 in conversation