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 (January 2009, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 16 Jan 2009 14:05:15 +0000
Reply-To:   karma <dorjetarap@GOOGLEMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   karma <dorjetarap@GOOGLEMAIL.COM>
Subject:   Re: question about sas macro variables
Comments:   To: "he.terry@gmail.com" <he.terry@gmail.com>
In-Reply-To:   <c2f8ed96-e1dd-4e3f-b16e-ebf2f80b064c@g38g2000yqn.googlegroups.com>
Content-Type:   text/plain; charset=ISO-8859-1

This seems somewhat similar to the first question I asked on SAS L :)

In your first piece of code

%let c = %b

SAS executes the macro %b first and returns what is "left over" from the %b macro, which is the values of &i. I see this as more of a SAS trick rather than what the macro language was intended to do - although there are some old timers who may correct me on this. You therefore have advertently/inadvertently created a macro function that returns the values of a function which can then be assigned to a variable.

In the second part of the code however, you are trying again to take the output of a loop and assign it to a macro variable. However this time it is recognised as an assignment and the "%do i=1 %to &m" is seen as text, and as there are no macro quoting functions used and SAS recognises this is macro syntax it issues the error message.

I think this raises another interesting question, can SAS macro create macro code that is executable at a later time? As far as I know, Lisp allows macro code to create macro code ad infinitum. I don't think SAS does allow this, but I would be happy to be proven wrong on this. An example:

%let c = %superq(%put 1;); %unquote(c);

2009/1/16 he.terry@gmail.com <he.terry@gmail.com>: > I have two programs. One is right and the other is wrong. I am not > sure about the reason. > > The right code is as follow: > > options symbolgen mprint; > %let m=2; > %macro b; > %do i = 1 %to &m; > &i > %end; > %mend b; > > %let c = %b > ; > > > %macro a; > %put &c; > %mend a; > %a; > > The wrong code is as follow: > options symbolgen mprint; > %let m=2; > %let c = %do i = 1 %to &m; > &i > %end; > ; > > > %macro a; > %put &c; > %mend a; > %a; >


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