Date: Tue, 26 Sep 2006 08:56:15 -0700
Reply-To: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Choate, Paul@DDS" <pchoate@DDS.CA.GOV>
Subject: Re: How to create a macro variable?
In-Reply-To: <1159257954.129223.135760@e3g2000cwe.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
Hi Kitty -
You can also use SQL to create sequential macro variables for each
observation.
proc sql noprint;
select Name, Sex, Age, Height, Weight
into :Name1-:Name19, :Sex1-:Sex19, :Age1-:Age19,
:Height1-:Height19, :Weight1-:Weight19
from sashelp.class;
quit;
%macro putit;
%do i=1 %to 9;
%PUT &&Name&i &&Sex&i &&Age&i &&Height&i &&Weight&i;
%end;
%Mend;
%putit;
I prefer Gerhard Hellriegel's call symput example with a counter
variable, but as Manuel pointed out SQL INTO macro variables are
flexible. In his example he showed how they can be used to store a list
of values in a single variable, rather than separate variables like
above.
hth
Paul Choate
DDS Data Extraction
(916) 654-2160
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
JMPicaza@GMAIL.COM
Sent: Tuesday, September 26, 2006 1:06 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: How to create a macro variable?
Hi Kitty,
A fast way to do this is using the proc sql. Example:
data example;
do x=1 to 10;
y=-x;
output;
end;
run;
%macro kk;
proc sql NOPRINT;
select x, y
into
:macroVarX separated by '@',
:macroVarY separated by ', '
from example;
quit;
data result;
x="¯oVarX.";
y="¯oVarY.";
run;
%mend kk;
%kk;
I hope this helps you,
Manuel
Kitty Lee wrote:
> Hi All,
>
> My dataset has a few variables based on some calcuations. How do I
create the marco variables from these variables and use them later?
>
> For example, if my dataset has two variables x and y and they have
values. However, I want to use the values later in the program so I
think I should make these variables into marco variables. Please let me
know how, thanks!
>
> Kitty
>
>
> ---------------------------------
> Want to be your own boss? Learn how on Yahoo! Small Business.