BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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...
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
deleted_user
Not applicable
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...
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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
  • 3 replies
  • 858 views
  • 0 likes
  • 2 in conversation