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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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