BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

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

2 REPLIES 2
SASKiwi
PROC Star

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.

Haikuo
Onyx | Level 15

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.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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