Help using Base SAS procedures

How come dropped a field is still shown in the "put log"?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

How come dropped a field is still shown in the "put log"?

Hi SAS Forum,

I have data set called "one" below.

data one;

input gender $ 1-1 age;

cards;

M 25

F 75

;

run;

Using dataset “One”, I create set “two” below.

data two;

           PUT "1  " _ALL_;

set one;

           PUT "2  " _ALL_;

if gender in ('M') then flag+1;

           PUT "3  " _ALL_;

output;

           PUT "4  " _ALL_;

drop flag;

           PUT "5  " _ALL_;

run;

Using put log, I have gotten the log below to see what is happening at each iteration.

Q: Step “5” is after I have given the “drop flag” command. Then how come still the green coloured flag=1 is there as shown below in the put log. There shouldn’t be a field called flag at the step “5”.

/*Frist Iteration*/

1  gender=  age=. flag=0 _ERROR_=0 _N_=1

2  gender=M age=25 flag=0 _ERROR_=0 _N_=1

3  gender=M age=25 flag=1 _ERROR_=0 _N_=1

4  gender=M age=25 flag=1 _ERROR_=0 _N_=1

5  gender=M age=25 flag=1 _ERROR_=0 _N_=1 /*How come flag field is still here. I have already given a command to drop it at step 5*/

/*Second Iteration*/

1  gender=M age=25 flag=1 _ERROR_=0 _N_=2

2  gender=F age=75 flag=1 _ERROR_=0 _N_=2

3  gender=F age=75 flag=1 _ERROR_=0 _N_=2

4  gender=F age=75 flag=1 _ERROR_=0 _N_=2

5  gender=F age=75 flag=1 _ERROR_=0 _N_=2

/*Third Iteration*/

1  gender=F age=75 flag=1 _ERROR_=0 _N_=3

Could anyone help me to understand?

Thanks

Mirisa


Accepted Solutions
Solution
‎04-23-2015 04:04 PM
Super User
Posts: 3,108

Re: How come dropped a field is still shown in the "put log"?

The DROP statement tells SAS to drop the variable FLAG from being written to the output dataset TWO. It is still present in the DATA step (technically the Program Data Vector or PDV) hence it shows in your PUT statement.

Also the DROP statement is not an executable statement - it is a definition-type statement defining what is to be dropped from being written out to TWO.

View solution in original post


All Replies
Solution
‎04-23-2015 04:04 PM
Super User
Posts: 3,108

Re: How come dropped a field is still shown in the "put log"?

The DROP statement tells SAS to drop the variable FLAG from being written to the output dataset TWO. It is still present in the DATA step (technically the Program Data Vector or PDV) hence it shows in your PUT statement.

Also the DROP statement is not an executable statement - it is a definition-type statement defining what is to be dropped from being written out to TWO.

Respected Advisor
Posts: 3,124

Re: How come dropped a field is still shown in the "put log"?

Drop statement will only be effect when outputing, and being one of the 'declarative', it doesn't matter where you put it. Drop= option will be effect on the data set where it attaches, so it is the inputing data set, then it won't show up in your log, unless you have it assigned again, which is btw in your case.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 196 views
  • 4 likes
  • 3 in conversation