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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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;
Jens89
Obsidian | Level 7

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

PeterClemmensen
Tourmaline | Level 20

@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 :

Jens89
Obsidian | Level 7

thanks, it worked. I had some error but it was unrelated to your solution.