Here I have a bunch of Checks to output if they equal 1. Each check that is equal to 0 should be ignored.
This is the current code I have for the output:
Data ouput_file; Set input_file; If first_check = 1; If second_check = 1; If third_check = 1; If fourth_check = 1; If fifth_check = 1 then output; Run;
At the moment, the code only works assuming that first_check = 1. The problem I am facing is that if first_check = 0, the code won't run. If first_check = 0, I still want it to ouput the other checks if they are equal to 1.
How do I get it to run for all checks when they are equal to 1 assuming any check (i.e the first or second) can be 0?
Thanks
You're conditions are stacked, like they have an AND. It looks like you want OR instead, if any is one then outout?
If so, you can simplify this by checking if the sum of the values are greater than or equal to 1.
if sum(first_check, second_check, .. , fifth_check) >= 1 then output;
You're conditions are stacked, like they have an AND. It looks like you want OR instead, if any is one then outout?
If so, you can simplify this by checking if the sum of the values are greater than or equal to 1.
if sum(first_check, second_check, .. , fifth_check) >= 1 then output;
The syntax (sub-setting IFs) you've used translate logically into AND. What you're after is OR.
If you're variables numeric and flags (0/1) then the logic @Reeza posted will work; else use something as below:
data ouput_file;
set input_file;
if
first_check = 1
or second_check = 1
or third_check = 1
or fourth_check = 1
or fifth_check = 1
then output;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.