BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mpoletika1
Calcite | Level 5

Hello,

 

Brand new to SAS. I need to keep records only between July 1, 2015 and June 30, 2016 for the variable "entry_date." The dates look like 2015-07-01 and 2016-06-30 and the format says  YYMMDD10. and the length is 8. Any code suggestions would helpful!

 

This is what I have right now.

 

data new;
set input;
if entry_date >= '2015-07-01'd and entry_date <= "2016-06-30" then delete;
run;

 

Thanks,

 

Mike

1 ACCEPTED SOLUTION

Accepted Solutions
LaurieF
Barite | Level 11

You're almost there, but you've got it the wrong way around.

data new;
set input;
if '1jul2015'd <= entry_date <= '30jun2016'd then
   output;
run;

Note to keep the date range, you want to output, not delete (note that delete removes observations from the output, not the input!)

data new;
set input;
if '1jul2015'd <= entry_date <= '30jun2016'd;
run;

When you've only got one output dataset, the output action is implied.

View solution in original post

3 REPLIES 3
LaurieF
Barite | Level 11

You're almost there, but you've got it the wrong way around.

data new;
set input;
if '1jul2015'd <= entry_date <= '30jun2016'd then
   output;
run;

Note to keep the date range, you want to output, not delete (note that delete removes observations from the output, not the input!)

data new;
set input;
if '1jul2015'd <= entry_date <= '30jun2016'd;
run;

When you've only got one output dataset, the output action is implied.

novinosrin
Tourmaline | Level 20

If no further processing or compound expressions involved, filter using "where"

 

where '01jul2015'd <= entry_date <= '30jun2016'd;
Reeza
Super User

Your biggest issues is that you're specifying the dates incorrectly. 

In SAS you need to specify a date as a 'date literal' which is using the DATE9 format, wrapping it in quotes and adding a d after wards. 

 

'01Jan2018'd

This allows SAS to differentiate between a date and a character value. 

 

As @LaurieF mentioned already, your logic was incorrect as well. 

 


@mpoletika1 wrote:

Hello,

 

Brand new to SAS. I need to keep records only between July 1, 2015 and June 30, 2016 for the variable "entry_date." The dates look like 2015-07-01 and 2016-06-30 and the format says  YYMMDD10. and the length is 8. Any code suggestions would helpful!

 

This is what I have right now.

 

data new;
set input;
if entry_date >= '2015-07-01'd and entry_date <= "2016-06-30" then delete;
run;

 

Thanks,

 

Mike


 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 3162 views
  • 3 likes
  • 4 in conversation