|
As Toby mentioned, symputx would probably be better. However, you refer
to variable i in your code and you don't have a variable i .. only the
macro variable &i. which is created as a result of the %do i= etc.
Art
-------
On Wed, 23 Jul 2008 22:43:20 -0700, learner <cnfengshuang@GMAIL.COM> wrote:
>On Jul 24, 12:27Â am, learner <cnfengshu...@gmail.com> wrote:
>> On Jul 23, 9:45�pm, learner <cnfengshu...@gmail.com> wrote:
>>
>>
>>
>>
>>
>> > Hi,
>>
>> > I wanted to run the following code to get
>>
>> > 1
>> > 2
>> > 3
>> > 4
>> > 5
>> > .
>> > .
>> > 10
>>
>> > %macro test;
>> > %do i = 1 %to 10;
>> > %let num= i;
>> > � � � � � put �&num ;
>> > %end;
>> > %mend test;
>> > data _null_;
>> > %test;
>> > run;
>>
>> > Here is what i got from the log:
>>
>> > 2048 �%macro test;
>> > 2049 �%do i = 1 %to 10;
>> > 2050 �%let num= i;
>> > 2051 � � � �put �&num ;
>> > 2052 �%end;
>> > 2053 �%mend test;
>> > 2054 �data _null_;
>> > 2055 �%test;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > MPRINT(TEST): � put i ;
>> > 2056 �run;
>>
>> > NOTE: Variable i is uninitialized.
>> > .
>> > .
>> > .
>> > .
>> > .
>> > .
>> > .
>> > .
>> > .
>> > .
>>
>> > How could I define a macro variable using the value of other variable
>> > in the data?
>>
>> > Thanks a lot!
>>
>> Thanks to Art for his reply with the following codes.
>>
>> %macro test;
>> %do i = 1 %to 10;
>>   %put  &i. ;
>> %end;
>> %mend test;
>> data _null_;
>> %test;
>> run;
>>
>> Actually, i wanted to assign values to macro from data variable. I
>> just found the call symput could do this.- Hide quoted text -
>>
>> - Show quoted text -
>
>Found this
>
>data team1;
> input position : $8. player : $12.;
> call symput(position,player); /*generate 3 macros, assigning
>values of players to macros position*/
>datalines;
>shortstp Ann
>pitcher Tom
>frstbase Bill
>;
>%put &shortstp &pitcher &frstbase;run;
>
>
>Is there any other way to read data variable value into macro?
|