10-17-2013 12:35 PM
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
If A='d' Then Do;
If B <=0 Then Do;
If C <=0 Then Do;
When am executing above program in output dataset Test1 both Variable B and C got droped. Can anybody help me how it is working.
10-17-2013 01:19 PM
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.
10-17-2013 02:03 PM
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.
11-18-2013 02:26 PM
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 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.