SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Delete data if not equal to specific informations

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Delete data if not equal to specific informations

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;


Accepted Solutions
Solution
2 weeks ago
PROC Star
Posts: 936

Re: Delete data if not equal to specific informations

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


All Replies
PROC Star
Posts: 578

Re: Delete data if not equal to specific informations

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

Contributor
Posts: 26

Re: Delete data if not equal to specific informations

Posted in reply to novinosrin

Yes, I only want to keep the lines 

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

Super User
Posts: 5,699

Re: Delete data if not equal to specific informations

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.

 

Contributor
Posts: 29

Re: Delete data if not equal to specific informations

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;
Solution
2 weeks ago
PROC Star
Posts: 936

Re: Delete data if not equal to specific informations

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;
Contributor
Posts: 26

Re: Delete data if not equal to specific informations

draycut you are fantastic!!!

this is the best solution!!!

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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