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;
Like this?
data Want;
set have;
where main_breed in ('HO', 'FR');
run;
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.