| Date: | Fri, 31 Jul 2009 14:18:27 -0500 |
| Reply-To: | Joe Matise <snoopy369@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Joe Matise <snoopy369@GMAIL.COM> |
| Subject: | Re: difficulty referencing global variable in macro within a data
step |
|
| In-Reply-To: | <288CB3D9A0230247BE3141043304989C04B17329A0@beagle.davidson.edu> |
| Content-Type: | text/plain; charset=ISO-8859-1 |
I wouldn't code it with a macro - if all you want to do is subtract
something from the variables, use an array. BUT, to answer the specific
question, you need extra &'s to resolve the whole macro variable, so,
&&predname&j (and sometimes a third, though I've not had much success
recognizing when it is one or the other except by trial & error).
The way to do that coding properly:
data datar00;
infile "c:\&filenamer00";
input &predname1 &predname2 random;
array preds &predname1 &predname2; *and if you have many vars, there are
lots of ways to automatically pick them, such as using _NUMERIC_ or the
colon (wildcard);
do _n_ =1 to dim(preds);
preds[_n_] = preds[_n_] - constant;
end;
run;
-Joe
On Fri, Jul 31, 2009 at 2:02 PM, Tonidandel, Scott <
sctonidandel@davidson.edu> wrote:
> I am stumped and could use some assistance resolving the following problem.
> This is all part of a much larger code but my problem is located within the
> following data step. I am trying to us a DO-loop to subtract a constant from
> some variables that are globally referenced using %let.
>
> %let predname1=TMA;
> %let predname2=TSL;
> %let numpred=2;
>
> data datar00;
> infile "C:\&filenamer00";
> input &predname1 &predname2 random;
> %macro test;
> %do j = 1 %to &numpred;
> &predname&j=&predname&j-constant;
> %end;
> %mend;
> %test;
> run;
>
>
> The macro executes if written as follows:
> %macro test;
> %do j = 1 %to &numpred;
> &predname1=&predname1-constant;
> %end;
> %mend;
>
> As it will iterate twice for &predname1.
> But, I can't seem to combine the global variable &predname with &j. When I
> try that as in the first code, I get:
> WARNING: Apparent symbolic reference PREDNAME not resolved.
>
> This is probably something obvious as I am not an experienced SAS
> programmer but I swear I have stared at it for hours and can't figure out
> why it won't work. Any help would be appreciated. Thanks in advance.
>
> Scott T
>
|