LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 24 Jul 2008 07:55:08 -0400
Reply-To:   Arthur Tabachneck <art297@NETSCAPE.NET>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Arthur Tabachneck <art297@NETSCAPE.NET>
Subject:   Re: read variable into macro
Comments:   To: cnfengshuang@GMAIL.COM
Content-Type:   text/plain; charset=ISO-8859-1

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?


Back to: Top of message | Previous page | Main SAS-L page