Hello,
Am using a where statement in a data step. My variable runs from '2000' to '2019'. I don't want to write all the years and I believe there may be a way in sas to do it quickly and effectively. All of the values of interest are sequential.
This attempt gave me an error.
data want;
set have;
where year in ( '2000' --'2019');
run;
Normally, you would never use a character variable to represent calendar or clock quantities, in this case the year.
Assuming you have numeric year values, then this works:
data want;
set have;
where 2000<=year<=2019;
run;
This also works
data want;
set have;
where year between 2000 and 2019;
run;
Normally, you would never use a character variable to represent calendar or clock quantities, in this case the year.
Assuming you have numeric year values, then this works:
data want;
set have;
where 2000<=year<=2019;
run;
This also works
data want;
set have;
where year between 2000 and 2019;
run;
If the values are integers you can use : to indicate a sequence.
1 data want;
2 set sashelp.class;
3 where age in (11:13) ;
4 run;
NOTE: There were 10 observations read from the data set SASHELP.CLASS.
WHERE (age=INT(age)) and (age>=11 and age<=13);
NOTE: The data set WORK.WANT has 10 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.03 seconds
Since you have quotes, I assume that's a character variable? Convert it to numeric if that's valid and then use BETWEEN.
where input(year, 8.) between 2000 and 2019;
@CathyVI wrote:
Hello,
Am using a where statement in a data step. My variable runs from '2000' to '2019'. I don't want to write all the years and I believe there may be a way in sas to do it quickly and effectively. All of the values of interest are sequential.
This attempt gave me an error.
data want;
set have;
where year in ( '2000' --'2019');
run;
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.