Date: Wed, 2 May 2001 15:23:39 -0400
Reply-To: Ian Whitlock <whitloi1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <whitloi1@WESTAT.COM>
Subject: Re: simple macro question - %let
Content-Type: text/plain; charset=ISO-8859-1
Myra,
Assuming your step
DATA _NULL_;
SET STATES;
DO I = 1 TO &OBSV;
IF _N_ = I THEN DO;
CALL SYMPUT('STATE'||LEFT(PUT(I,2.)),ST);
END;
END;
RUN;
should have been
DATA _NULL_;
DO I = 1 TO &OBSV;
SET STATES;
IF _N_ = I THEN DO;
CALL SYMPUT('STATE'||LEFT(PUT(I,2.)),ST);
END;
END;
RUN;
you could simplify the code to
PROC SUMMARY DATA=NCLM.EARNPQ MISSING NWAY;
VAR SEARNED;
CLASS MASTERST;
WHERE MASTERST NE 'NY';
FORMAT SEARNED DOLLAR20.2;
OUTPUT OUT=STATES(RENAME=(MASTERST=ST) DROP=_TYPE_ _FREQ_) SUM=;
RUN;
DATA _NULL_ ;
SET STATES(KEEP=ST) ;
CALL EXECUTE ( '%MSTCLM(&Q,ST=' || ST || ')' );
RUN ;
Incidentally, CALL EXECUTE also provides a second solution to the original
question. PROC SQL provides a third alternative. These tools often
eliminate the need for arrays of macro variables. Dare I say, making them
almost obsolete?
Ian Whitlock
On Wed, 2 May 2001 14:00:33 -0400, Myra Oltsik <moltsik@RESPONSE.COM> wrote:
>On Wed, 2 May 2001 10:22:31 -0400, Dan Fiscus <fiscus@AL.UMCES.EDU> wrote:
>
>>Hi,
>>
>>This must be an easy one, but as fairly early on in getting the
>>macro language, I am stumped...
>>
>>I want to store a dataset variable value into a macro variable.
>>I have a dataset variable called x and want to store the current
>>observation's value of x into the macro variable chosenx. But
>>if I say (from inside a data step):
>>
>>%let chosenx = x ;
>>
>>the value of chosenx becomes the string 'x'.
>>
>>Thanks for any suggestions...
>>
>>Dan Fiscus
>>
>>
>>--
>>
>>Dan Fiscus
>>Ecologist/Research Assistant email: fiscus@al.umces.edu
>>Appalachian Laboratory phone: 301-689-7121
>>University of Maryland C.E.S. fax: 301-689-7200
>>301 Braddock Road http://www.al.umces.edu
>>Frostburg, MD 21532 USA
>
>Dan,
>
>It's not exactly easy. Here's some code I use to do what I think you want
>to do: [I have comments below.]
>
>PROC SUMMARY DATA=NCLM.EARNPQ MISSING NWAY;
> VAR SEARNED;
> CLASS MASTERST;
> WHERE MASTERST NE 'NY';
> FORMAT SEARNED DOLLAR20.2;
> OUTPUT OUT=STATES(RENAME=(MASTERST=ST) DROP=_TYPE_ _FREQ_) SUM=;
>RUN;
>
>DATA _NULL_;
> SET STATES(KEEP=ST) NOBS=NO;
> CALL SYMPUT('OBSV',LEFT(PUT(NO,8.)));
> STOP;
>RUN;
>
>%GLOBAL OBSV;
>
>DATA _NULL_;
> SET STATES;
> DO I = 1 TO &OBSV;
> IF _N_ = I THEN DO;
> CALL SYMPUT('STATE'||LEFT(PUT(I,2.)),ST);
> END;
> END;
>RUN;
>
>%MACRO MRESVD;
>
> %GLOBAL Z;
>
> %DO Z = 1 %TO &OBSV;
> %MSTCLM(&Q,ST=&&STATE&Z);
> %END;
>
>%MEND MRESVD;
>
>%MRESVD;
>
>==========
>
>On it's first pass, &&STATE&Z resolves to &STATE1. On the next pass,
>&STATE1 response to AZ (for Arizona). I learned this in Art Capenter's
>Macro class about 1-½ years ago. I don't have the code memorized, but
>always available when I need it.
>
>Myra
|