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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
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;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

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');

Giovani
Obsidian | Level 7

Yes, I only want to keep the lines 

where size in ('Compact', 'Medium_SUV','Medium_size');

Astounding
PROC Star

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.

 

rvsidhu035
Quartz | Level 8
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;
PeterClemmensen
Tourmaline | Level 20
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;
Giovani
Obsidian | Level 7

draycut you are fantastic!!!

this is the best solution!!!

 

SAS Innovate 2025: Register Now

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!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 6 replies
  • 6435 views
  • 4 likes
  • 5 in conversation