LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 25 Mar 2008 09:34:42 -0700
Reply-To:     Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jack Hamilton <jfh@STANFORDALUMNI.ORG>
Subject:      Re: if 0 then set data ...
Comments: To: Chang Chung <chang_y_chung@HOTMAIL.COM>
Content-Type: text/plain; charset="iso-8859-1"

"multiple identity syndrome" - I like that,. very descriptive.

The data step started out modeled on PL/I, then added elements from C, then from C++ and Java (or some other OO language), and there are a few hints of Perl or some other scripting language.

Did they talk about Data Step 2 at SGF (née SUGI)? Is it any more consistent in its syntax?

One thing I will say in SAS's favor is that generally all the elementary language elements follow the PL/I model.

-----Original Message----- From: Chang Chung <chang_y_chung@HOTMAIL.COM> Sent: Tuesday, March 25, 2008 8:37 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: [SAS-L] if 0 then set data ...

On Tue, 25 Mar 2008 05:08:41 -0400, Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE> wrote:

>If you look at the following example, you see that SET has two meanings. > >data a; > put n=; > put age=; > set sashelp.class nobs=n; >run; > >First is the global: open the dataset, read the header to get all >structure information. Second is to build the PDV and read all obs in a >automatic loop. You can also say: SET is both, executable and not. The not- >executed SET gives information about the dataset to the compiler, the >second is executed (obs are read and written in a loop). >Look at the first output: N (number of obs) is available, the "global" SET >has done his work. The "local" SET has not: AGE is still missing, no obs >has been read. ...

hi,

the documentation says that there are two kinds of statements in the data step: executable and declarative. Executable statements are executed during the execution time; Declarative statements provide the compiler some information during the compile time.

Notice that si was careful and did *not* say that executable statements do not help compiler. Because some of them do. One of them is the set statement, which is executable, but does give compiler the data set header information (variable names, their order, types, number of observations and so on).

so the ugly hack, "if 0 then set ds" works since the "set ds" gives the header information of the data file ds to the compiler (and then the compiler which does not know that it is not to be executed sets up the pdv accordingly), but is skipped in the execution time because the if condition is false.

i say it is "ugly" since it takes advantage of and thus exposes of the spectacularly messy identity of the data step language, which was invented as a declarative (a 4th gen programming) language, but has been evolved to include more and more procedural elements into it. For those who are used to, it is a fantastically rich and often a very succinct but expressive language. For those who just started learning, it is one of the difficult languages to speak fluently. It is mainly because the language itself suffers from the multiple identity syndrome.

Maybe this is more confusing. Well, everybody has different learning style and maybe for some, this maybe a bit easier, i hope. :-)

cheers, chagn


Back to: Top of message | Previous page | Main SAS-L page