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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.