DATA Step, Macro, Functions and more

IF statement execution in PDV

Accepted Solution Solved
Reply
Super Contributor
Posts: 285
Accepted Solution

IF statement execution in PDV

Hello,

 

I have the following code to see how IF statement executes in PDV. It, however, just shows the reading in the observations from input data set. How to see the action of IF statement in PDV? 

 

data test;
   put _all_;
   set sashelp.class;
   put _all_;
   if age > 14;
   put _all_;
run;

Accepted Solutions
Solution
‎09-10-2017 10:24 PM
Super User
Posts: 2,513

Re: IF statement execution in PDV

[ Edited ]
Posted in reply to ChrisBrooks

As @ChrisBrooks said, the PDV and the IF statement are not linked.

1 - Data is loaded in PDV

2 - Data step statements are executed

3- IF clause is read

4- IF returns false, therefore the data step stops the iteration (and skips the implicit output statement at the end).

 

As for your program, when you run it you can see that for example

Name=Janet Sex=F Age=15 

appears 3 times in the log whereas

Name=Jane Sex=F Age=12

only appears twice.

 

Now with a where clause, the PDV is impacted.

Not with an IF statement.

View solution in original post


All Replies
Valued Guide
Posts: 596

Re: IF statement execution in PDV

Posted in reply to SAS_inquisitive

I'm not sure what it is you're expecting to see - the data set variables are read into the PDV along with any computed variables plus _n_ and _error_ and that's what you shopuld be seeing in your log.

 

You're not creating any computed variables in your IF statement so there's nothing to see - if you want to create a computed variable which isn't ultimately stored in the out data set then do this and you'll see the valu in your put _all_ statement.

 

data test(drop=pdv_var);
   put _all_;
   set sashelp.class;
   put _all_;
   if age > 14 the pdv_var=99;
   put _all_;
run;
Super Contributor
Posts: 285

Re: IF statement execution in PDV

Posted in reply to ChrisBrooks

@ChrisBrooks May be my question is not clear enough. I don't want to create new variable; but want to envision what might be goin on in PDV when IF statement executes. In general sense, we know it selects observations with AGE greater than 14.

Super User
Posts: 6,935

Re: IF statement execution in PDV

Posted in reply to SAS_inquisitive

One clue you need to examine is the value of _N_.  Also keep in mind that variables read from a SET statement are automatically retained.

 

With that in mind, you should be able to see that all three PUT statements execute when AGE > 14.

 

In addition, when AGE <= 14, the first two PUT statements execute, but the third one doesn't.

Valued Guide
Posts: 596

Re: IF statement execution in PDV

Posted in reply to SAS_inquisitive
The subsetting IF executes AFTER the data has been read into the PDV so there's nothing to see.
Solution
‎09-10-2017 10:24 PM
Super User
Posts: 2,513

Re: IF statement execution in PDV

[ Edited ]
Posted in reply to ChrisBrooks

As @ChrisBrooks said, the PDV and the IF statement are not linked.

1 - Data is loaded in PDV

2 - Data step statements are executed

3- IF clause is read

4- IF returns false, therefore the data step stops the iteration (and skips the implicit output statement at the end).

 

As for your program, when you run it you can see that for example

Name=Janet Sex=F Age=15 

appears 3 times in the log whereas

Name=Jane Sex=F Age=12

only appears twice.

 

Now with a where clause, the PDV is impacted.

Not with an IF statement.

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 192 views
  • 3 likes
  • 4 in conversation