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 (July 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 19 Jul 2004 10:55:32 -0400
Reply-To:     "Lustig, Roger" <roger.lustig@CITIGROUP.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Lustig, Roger" <roger.lustig@CITIGROUP.COM>
Subject:      Re: creating a scalar variable
Comments: To: Zio Fester <ziofester2@hotmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Zio:

SAS-L is the mailing-list version of this newsgroup.

SAS *processes* row-by-row. That doesn't mean you can't have a scalar available to your program.

More precisely, SAS does its processing on a "program data vector" or PDV, which contains everything needed to process the current row.

RETAIN leaves a variable in the PDV. DROP keeps a variable from being output to the data set(s) referenced in the DATA statement. So, if you RETAIN and then DROP a variable, it will be available during processing, but won't show up in the data set itself.

Now, how to get the variable in there? One way:

data new(drop=scalar_val); set old; if _N_=1 then set scalar; <more code>; run;

This assumes that you have a 1x1 (well, 1-row--you might have several scalars) table called SCALAR out there. You don't even need the RETAIN here, because variables read in from a SET statement are RETAINed automatically.

Then there are macro variables. If your scalar is an integer, or if high precision isn't needed, this is easy.

proc sql; select max(salary) into :max_salary from master.employ; quit;

data new; set old; if new_salary >= &max_salary then do; <etc.> end; run;

Note the colon prefix in the INTO clause in the SQL query. That makes a macro variable. Note that, when the macro variable is resolved, you'll be comparing NEW_SALARY to a constant.

You can also create/populate the macro variable by using CALL SYMPUT in a DATA step.

To sum up: --SAS steps (DATA and PROC) create and/or operate on tables. --Outside of these steps, global macro variables may be kept and manipulated. --*You* can use these tools to get scalars or their equivalent to the places where you want them to be.

Roger

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of Zio Fester Sent: Monday, July 19, 2004 10:05 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: creating a scalar variable

In article <446DDE75CFC7E1438061462F85557B0F027E6C68 @remail2.westat.com>, HERMANS1@WESTAT.COM says... > Zio: > I hope that your instructor doesn't subscribe to SAS-L!

Please forgive my ignorance, but what does that happen to be?

> Whatever his or her > skill level, it does turn out that SAS, like many other so-called 'database > programming languages', operates on actual or virtual tables. A table can > degenerate to a one-column, one-row cell that has many of the properties of > a scalar. More typically, a database programmer combines tabular datasets to > produce solutions to programming problems.

Does this mean that SAS can only "think" row by row and that there's no way to create a scalar variable (or a 1x1 matrix...) accessible from any part of my code?

> It takes a while to learn how to combine tabular datasets effectively. Once > you learn how, you will be able to do more in less time and with fewer > errors. > Sig


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