Date: Mon, 15 Dec 2008 22:24:55 -0500
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
<schreier.junk.mail@GMAIL.COM>
Subject: Re: Macro Do Loop for Discrete Values
On Mon, 15 Dec 2008 09:00:29 -0600, Joe Matise <snoopy369@GMAIL.COM> wrote:
>My idea is not to use a macro in this way. SAS macros are not intended for
>this purpose... If you have something that actually requires a macro,
>please post that, but what you posted should not be done with a macro.
>
>-Joe
>
>On Sun, Dec 14, 2008 at 9:12 PM, Daniel Yanosky <dyanosky@kennesaw.edu>wrote:
>
>> Joe,
>>
>> This is actually dummy code inside the %do and %end statements simply for
>> the purposes of illustrating the problem with the do loop. Eventually, when
>> I get the kinks worked out, I have code that generates data and processes it
>> using multiple data and proc steps. Any ideas?
Often that can be done by first conditioning and possibly expanding the
data, then running each DATA and PROC step just once, but with the
appropriate BY statement for each step. No macro needed.
>>
>> Thanks,
>>
>> Daniel
>>
>>
>>
>> >>> Joe Matise <snoopy369@GMAIL.COM> 12/14 8:41 PM >>>
>> Doesn't seem like you should be using macros here. This is much easier to
>> handle with data step processing.
>>
>> %let variance = %str(1.5 2 3 5);
>> data results;
>> i = 1;
>> do i = 1 to countc("&variance",' ')+1;
>> token = scan("&variance",i);
>> output;
>> end;
>> run;
>>
>> If you have an already existing dataset called results, you can either set
>> it in or create a second dataset here and append that to the results
>> dataset.
>>
>> -Joe
>>
>> On Sun, Dec 14, 2008 at 6:16 PM, D. Yanosky <dyanosky@kennesaw.edu> wrote:
>>
>> > Hello,
>> >
>> > I need to run a macro-valued do loop using discrete values. I found the
>> > following code (paraphrased) on the list-serv, but it does not seem to
>> > work in my case because one of my values contains a decimal. Any idea on
>> > how to make this work?
>> >
>> > %LET VARIANCE = %STR(1.5 2 3 5);
>> >
>> > %MACRO SIM(ITER=);
>> >
>> > %LOCAL I TKN1;
>> >
>> > %LET I = 1;
>> > %LET TKN1 = %SCAN(&VARIANCE, &I);
>> > %DO %WHILE (%LENGTH(&TKN1) NE 0);
>> >
>> >
>> > DATA D;
>> > I = &I;
>> > TOKEN = &TKN1;
>> > RUN;
>> >
>> > PROC APPEND BASE=RESULTS DATA=D FORCE;
>> > RUN; QUIT;
>> >
>> > %LET I = %EVAL(&I + 1);
>> > %LET TKN1 = %SCAN(&VARIANCE, &I);
>> >
>> > %END;
>> >
>> > %MEND;
>> >
>> > %SIM(ITER=1)
>> >
>> > PROC PRINT DATA=RESULTS;
>> > RUN; QUIT;
>> >
>> > Thanks,
>> >
>> > Daniel
>> >
>>
|