BookmarkSubscribeRSS Feed
Barkamih
Pyrite | Level 9

Hil all 

 

I'm Looking for your help by using this code.

 this variable main_breed has many different names, I just want to keep only records that have HO and FR, So, I'm using this code and it worked perfectly to keep HO bata by using main_breed information, 

my question How I can keep HO and FR together by editing this code?

regards 

 

data Want;
set have;
if main_breed  ne 'HO' then delete;
run;quit;

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data Want;
set have;
where main_breed in ('HO', 'FR');
run;
r_behata
Barite | Level 11

This code will write to the output where the main_breed is both HO and FR.

 

data Want;
set have;
if main_breed  in ('HO','FR') ;
run;
ShiroAmada
Lapis Lazuli | Level 10

Try this.

data Want;
set have;
where upcase(main_breed)  in ('HO','FR');
run;

 

 

What I did:

#1. Remove the quit; statement.  Why?  It's not required in the data step.

#2. I replaced IF with a WHERE condition.  Why?  IF or WHERE will work but I think WHERE is more appropriate.

#3. I include a character function UPCASE.  Why?  This is to standardize the values to "HO" and "FR".  Unless "ho" and "HO" in your records are 2 separate codes.

 

Also, you might want to try PROC SQL.  Optionally, you can sort the records too by using the order by clause.

 

proc sql;
  create table WANT as
select * from HAVE
where upcase(main_breed) in ("HO","FR");
*order by <insert a variable to sort.  user comma to delimit the 2 or more variables>;
quit;

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 696 views
  • 1 like
  • 5 in conversation