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;
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.
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;
@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.
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.
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.
Your terminology is off. The Program Data Vector is just the place where SAS is storing the values for current iteration of the data step. Think of it as containing all of the variables your program reads and/or creates and also all of the automatic variables (_n_, _error_ etc).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.