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 1996, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 4 Jul 1996 01:58:45 GMT
Reply-To:     Richard Wright <>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Richard Wright <rcw@TENET.EDU>
Organization: The University of Texas at Austin, Austin, Texas

In <>, Frank LU <LUF@RPR.RPNA.COM> writes: > >data testdata; >input a1 a2 @@; >cards; >1 2 3 4 5 6 >; > >%let total1 = 9; >%let total2 = 12; >DATA B; SET TESTDATA; > >ARRAY FUN{2} a1 a2; >DO I = 1 TO DIM(FUN); * I have to use array in my proc report; > >* AA = FUN(I) / &total1; * this works but not what I want; > AA = FUN(I) / &total_||left(trim(i)); * this does not work; >END; >run; >PROC PRINT; > title "total1= &total1 total2=&total2"; >run; Frank:

I don't know - I just can't help myself - to answer, to not answer....

Well here goes, again.

Think of a macro as an abbreviation that (at the risk of incurring the wrath of the other macro gurus) never changes. This isn't strickly true, but for now its a useful abstraction.

The nice thing about a macro is that you set it at the top of your program and use it repeatedly across numerous data steps and procs. This is useful because unlike oh say, C, or Basic, or Fortran, your variables get scratched at processing boundries. There are four such boundries: DATA steps, PROC steps, RUN, and CARDS. Basically, SAS collects statements starting at one of these boundries (eg. DATA) and stops collecting them when it hits another boundry (eg CARDS). Then it compiles the statements it collected and runs them. Part of that process is interperting a macro (variable or statement). Basically, the macro is expanded either during the collection phase or the compilation phase. It ordinarily is not expanded during the running phase. So part of your problem is that you are trying to change what is essentially a constant during the run phase. Of course part of you problem is that you have a macro variable named total_, also.


So what to do?

One approach is to define another array and use it:

DATA ... ; /* more code */ ARRAY totals{2} _TEMPORARY_ (&total1, &total2) ; DO I = 1 TO DIM(FUN); * I have to use array in my proc report; AA = FUN(I) / totals(i); * this should work; END;

This probably the easiest way to deal with things. There is another way using SymGet, but that's another post.

By the way - Arrays only exist in data steps. Variables go into a data step, Variables come out of a data step.

FYI, The manual on MACROS has a very good summary of how the SAS supervisor runs a program - well worth the read.

Hope this helps. Richard Wright -

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