DATA Step, Macro, Functions and more

How does SAS order variables in PDV?

Reply
N/A
Posts: 0

How does SAS order variables in PDV?

Hi there.

This is more a curiosity that a problem.

Most experienced SAS programmers will be familiar with the concept of the Program Data Vector (PDV) and how SAS populates it with variables as a SAS Data Step is compiled.

This little excerpt from a SUGI paper sums up how I understand it:

"Variables are added to the PDV in the order seen by
the compiler during parsing and interpretation of
source statements."

If so can anyone explain to me what is going on here:

data WORK.RESULTS;
first = second + third;
run;

As I understand it variables should appear in the output data set ordered 'first', 'second' and 'third'.

Instead, they appear ordered 'first', 'third' and 'second'.

What's going on?

Cheers,


Chris...
Super Contributor
Super Contributor
Posts: 3,174

Re: How does SAS order variables in PDV?

Posted in reply to deleted_user
Why presume SAS compiler is interrogating the SAS program source statements top-down and left to right within your DATA step? Also, don't presume that SAS actually stores the variables in any particular manner (such as the CONTENTS report order list), given that there are features like COMPRESS which could influence the SAS system's behavior (just to start).

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: How does SAS order variables in PDV?

Thanks for the reply Scott.

You raise an interesting couple of points.

True, I am presuming that the SAS compiler is interrogating the SAS program source statements top-down and left to right. All source material I have seen to date, relating to SAS compilation, explains it that way.

Here is a link to some relevant material in the SAS documentation:
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001071821.htm#super

Also true, I like to presume that SAS actually does store the variables in a particular manner. Case in point would be the use of the RETAIN to 'reorder' variables in a particular way in a data step, because we know what effect the RETAIN statement placed before a SET has.

What is clear here is that my understanding of the compilation phase is not complete enough to explain what is causing this unexpected (for me anyway) effect.

Thanks again for your input.

Chris...
Super Contributor
Super Contributor
Posts: 3,174

Re: How does SAS order variables in PDV?

Posted in reply to deleted_user
Again, your use of the RETAIN may or may not have any influence on SAS internal behavior for ordering its observations and variables. I know that since SAS v6 when SAS was re-written to separate the various system-interface layers, there was significant optimization efforts achieved for various supported OS platforms. So, you may think that you are influencing SAS variable order, but I'd humbly submit that SAS has its own internal "smarts" doing what it needs for optimization depending on the OS environment and possibly other OPTIONS / CONFIG settings you may have declared (or defaulted to). FYI - have had enough energy from my part on this topic. Later.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 3 replies
  • 137 views
  • 0 likes
  • 2 in conversation