Date: Mon, 19 Jul 2004 16:44:46 +0200
Reply-To: "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Groeneveld, Jim" <jim.groeneveld@VITATRON.COM>
Subject: Re: creating a scalar variable
Content-Type: text/plain; charset="iso-8859-1"
Hi Zio,
If you really want some kind of scalar that exists and keeps its value between PROCs and DATA steps, then the macro variable is the only one. But that is not a variable like the other ones, it is a piece of text, which you usually would insert in your code. Say:
%LET MacroVar = 10;
The piece of SAS code where that value is being used, e.g.:
PROC PRINT DATA=yourdata (WHERE=(Variable EQ &MacroVar)); RUN;
actually becomes:
PROC PRINT DATA=yourdata (WHERE=(Variable EQ 10)); RUN;
and is being executed with the hard-coded value.
You can do arithmetic with macro values, but I'll warn you: if you are just a beginner with SAS, macro language may be difficult to learn and is quite another concept. Combining macro and SAS language actually is two languages intermixed. And the macro language gets (compiled and) processed firstly, before a RUN; or QUIT; statement, and only after that the SAS code gets (compiled and) processed. And there are functions and routines to process macro values in a data step,.......
Well, what I wanted to say is, that while being a beginner with SAS, it is very difficult to learn macro language. At least that is my perception, based on the various levels of experience with SAS of the subscribers to this list (you are reading now), SAS-L. So, for the time being, forget about it. And concentrate on pure SAS language firstly. SAS programs actually contain chunks of code, which are compiled and run by chuncks. Quite different from e.g. a C program, which is being compiled all at once.
Regards - Jim.
--
. . . . . . . . . . . . . . . .
Jim Groeneveld, MSc.
Biostatistician
Science Team
Vitatron B.V.
Meander 1051
6825 MJ Arnhem
Tel: +31/0 26 376 7365
Fax: +31/0 26 376 7305
Jim.Groeneveld@Vitatron.com
www.vitatron.com
My statistics are quite predictable, but my computer may be quite unpredictable.
[common disclaimer]
-----Original Message-----
From: Zio Fester [mailto:ziofester2@HOTMAIL.COM]
Sent: Monday, July 19, 2004 15:39
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: creating a scalar variable
In article
<81BFA8F7807F1349AD6C16AD00A1AB9B017325BE@AMSM1BMSGM01.ent.core.medtroni
c.com>, jim.groeneveld@VITATRON.COM says...
>Of course you can have a scalar variable, but it just depends on how
you
>store it, what you would call it. If you create it (e.g. a mean over
all
>observations) from a PROC MEANS, write it to a dataset (OUT= option)
with
>only one observation, merge it with the original data and write it with
>the original data it has become a value per record, which it equal over
>all records. In memory, like with all data from a record, it only takes
>one register.
But this is a very long and time-consuming procedure, especially if it
needs to be done many times! We are in the 21st century and programming
languages have evolved quite a bit! ;) I really cannot understand how it
is possible to still use a software which forces the user to go through
such a long procedure in order to get a very simple result!
>Scalars which will not/never be written to an output dataset are some
>automatic variables, like _N_ and variables, which serve as returned
>values, e.g. the OBS=variable or END=variable or IN=Variable option on
a
>SET statement. These could be ignored for the purpose defined and used
>differently.
I'm sorry, but I didn't quite understand your explaination. I'm really
new to SAS and am not familiar with it.
I would simply like to create a scalar variable which can be accessible
from any part of my code, that is, even outside the PROC that created
it. Is this possible? How? If possible, I would like to avoid the long
procedure described at the very beginning.
|