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
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.
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.
If no further processing or compound expressions involved, filter using "where"
where '01jul2015'd <= entry_date <= '30jun2016'd;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.