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.

sas-innovate-2024.png

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.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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