BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

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

7 REPLIES 7
ChrisBrooks
Ammonite | Level 13

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;
SAS_inquisitive
Lapis Lazuli | Level 10

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

Astounding
PROC Star

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.

ChrisBrooks
Ammonite | Level 13
The subsetting IF executes AFTER the data has been read into the PDV so there's nothing to see.
ChrisNZ
Tourmaline | Level 20

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.

CJac73
Obsidian | Level 7
Think of the PDV as an internal tracking or lookup table of system and data variables that you can query for info.
Tom
Super User Tom
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 7 replies
  • 1570 views
  • 5 likes
  • 6 in conversation