Hi SAS Wrold,
I had Below dataset called Test.
A B C ------------------ Variables
a 1 2
b 2 4
c 3 6
d 4 0
I have written program
Data Test1;
Set Test;
If A='d' Then Do;
If B <=0 Then Do;
Drop B;
end;
If C <=0 Then Do;
Drop C;
end;
end;
run;
When am executing above program in output dataset Test1 both Variable B and C got droped. Can anybody help me how it is working.
Regards,
SAS_Sravan
Drop statements are not conditional, if in the code they will drop the variable. Since the purpose of Drop is to remove the Variable from the dataset that makes sense. You may actually want to set B and C to missing values.
Maybe you should provide an example of your input data and the desired outcome and possibly describe what you are going to do with the resulting data.
Do you want to remove the row instead? you can conditionally delete observations using if b<=0 then delete.
Also you dont need do loop for one action.
EJ
IF won't affect the execution of DROP here.
During compilation phase of a data step SAS scans the code to determine and create all variables - also for the output data set(s). Think of it as the "header" of the data set (descriptor information).
SAS(R) 9.2 Language Reference: Concepts, Second Edition
SAS data sets are orthogonal so you can't have a variable in one row and then not in another row. That's why it makes sense that DROP can't be used conditionally during the execution phase of the data step but is used during compilation phase.
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.