The SAS Output Delivery System and reporting techniques

How Drop statement will work here?

Reply
Contributor
Posts: 26

How Drop statement will work here?

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

Super User
Posts: 11,114

Re: How Drop statement will work here?

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.

Super Contributor
Posts: 333

Re: How Drop statement will work here?

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

N/A
Posts: 1

Re: How Drop statement will work here?

IF won't affect the execution of DROP here.

Respected Advisor
Posts: 4,131

Re: How Drop statement will work 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.

Ask a Question
Discussion stats
  • 4 replies
  • 588 views
  • 0 likes
  • 5 in conversation