Hi experts!!
For the data below I want to keep only the pieces of information where the Size(column) is equal to Compact, Medium_SUV, and Medium_size. Any thoughts how I can do that?
data Cars;
input Type $ Size $ Colour $;
datalines;
Car Medium_size Yellow
Car Small_size Blue
Car Small_SUV White
Car Compact White
Car Large_SUV Blue
Car Medium_SUV Gray
run;
data Cars;
input Type $ Size $ Colour $;
datalines;
Car Medium_size Yellow
Car Small_size Blue
Car Small_SUV White
Car Compact White
Car Large_SUV Blue
Car Medium_SUV Gray
run;
data want;
set Cars;
where Size not in ("Compact", "Medium_SUV", "Medium_size");
run;
Do you mean, you only want to keep those obs where size in ('Compact', 'Medium_SUV','Medium_size')?
simple where or if statement?
where size in ('Compact', 'Medium_SUV','Medium_size');
or
if size in ('Compact', 'Medium_SUV','Medium_size');
Yes, I only want to keep the lines
where size in ('Compact', 'Medium_SUV','Medium_size');
Note that your sample program truncates the values down to 8 characters. You would need to add this statement before the INPUT statement:
length size $ 10;
You can use either an IF or a WHERE statement to subset, as was suggested. However, note that WHERE is not possible in your sample program, because you are inputting from raw data. WHERE is only permitted when the source of data is already a SAS data set.
data Cars;
length size $15.;
input Type $ Size $ Colour $;
if size in ('Compact', 'Medium_SUV','Medium_size');
datalines;
Car Medium_size Yellow
Car Small_size Blue
Car Small_SUV White
Car Compact White
Car Large_SUV Blue
Car Medium_SUV Gray
;
run;
data Cars;
input Type $ Size $ Colour $;
datalines;
Car Medium_size Yellow
Car Small_size Blue
Car Small_SUV White
Car Compact White
Car Large_SUV Blue
Car Medium_SUV Gray
run;
data want;
set Cars;
where Size not in ("Compact", "Medium_SUV", "Medium_size");
run;
draycut you are fantastic!!!
this is the best solution!!!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.