Date: Wed, 2 May 2001 15:43:00 -0400
Reply-To: "Oltsik, Myra" <moltsik@RESPONSE.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Oltsik, Myra" <moltsik@RESPONSE.COM>
Subject: Re: simple macro question - %let
Content-Type: text/plain; charset="iso-8859-1"
Wow! There's still so much to learn and so many ways of doing things. Thanks
IAN.
Myra
-----Original Message-----
From: Ian Whitlock [mailto:whitloi1@WESTAT.COM]
Sent: Wednesday, May 02, 2001 3:24 PM
To: SAS-L@LISTSERV.UGA.EDU; Myra Oltsik
Cc: Ian Whitlock
Subject: Re: simple macro question - %let
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
|