I'm looking for a way to add number ranges in the where statement instead of adding them individually.
the below would be ideal but that doesn't work
data mydataset;
set mydata;
where var IN(1-20, 30-33, 50-65);
quit;I have quite many ranges, I could work around it with defining the ranges individually but I am hoping there is a more efficient way.
thanks
Remember, a data step end with a Run;. Not Quit;
You can do this
data mydata;
var=20; output;
var=21; output;
run;
data mydataset;
set mydata;
where var in (1:20, 30:33, 50:65);
run;
Remember, a data step end with a Run;. Not Quit;
You can do this
data mydata;
var=20; output;
var=21; output;
run;
data mydataset;
set mydata;
where var in (1:20, 30:33, 50:65);
run;
run indeed, I've been using too much proc sql I'd say!
I'm not sure if I understand the code you've written. if I have var = 20 in the first datastep, how can I then use 1:20 in the second part and why would you write var = 21 in the first step, I don't see how that fits in?
thanks
@Jens89, I just created a simple data set so you can see how the code works. ,
The only thing you should change in your code really is - to :
thanks, it worked. I had some error but it was unrelated to your solution.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.