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 (March 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 14 Mar 2010 08:59:51 -0500
Reply-To:     Kevin Myers <KevinMyers@AUSTIN.RR.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Kevin Myers <KevinMyers@AUSTIN.RR.COM>
Subject:      Re: Macro
Comments: To: SAS user <Sasuser4@GOOGLEMAIL.COM>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
              reply-type=original

You call the macro providing the name of your data set:

%doit(mydata);

The SOURCE macro variable gets the value MYDATA, and that value is substituted anywhere that &SOURCE is used in the macro.

----- Original Message ----- From: "SAS user" <Sasuser4@GOOGLEMAIL.COM> To: <SAS-L@LISTSERV.UGA.EDU> Sent: Sunday, March 14, 2010 08:44 Subject: Re: Macro

> Thanks for your reply. > > I used the following code but still getting errors. > > Can you tell me where I should specify the dataset to be used? > thanks > > %MACRO Doit(source); > > proc sort data= &source ;**** change here; > by lpermno; > run; > > data fill / view=fill; > do until (last.lpermno); > set &source ;*** change here; > by lpermno; > if first.lpermno then firstq=4*input(datafqtr,4.)+input(substr > (datafqtr,6,1),1.)-1; > end; > lastq=4*input(datafqtr,4.)+input(substr(datafqtr,6,1),1.)-1; > do q=firstq to lastq; > datafqtr=put(int(q/4),4.)||'Q'||put(mod(q,4)+1,1.); > output; > end; > keep lpermno datafqtr; > run; > > proc sort data= mydata; > by lpermno datafqtr; > run; > > data mydata2; > merge &source;** change here; > by lpermno datafqtr; > lagatq=lag(atq); > if first.lpermno then lagatq=.; > put lpermno datafqtr (atq lagatq) (4.); > run; > > %mend DOIT; > > %doit(&source); > > > %doit(&source); > WARNING: Apparent symbolic reference SOURCE not resolved. > ERROR: The text expression &SOURCE contains a recursive reference to the > macro variable SOURCE. > The macro variable will be assigned the null value. > NOTE: Line generated by the invoked macro "DOIT". > > > ERROR: File WORK.NAME.DATA does not exist. > > ERROR 22-322: Expecting a name. > > > On Sun, 14 Mar 2010 08:09:13 -0500, Kevin Myers <KevinMyers@AUSTIN.RR.COM> > wrote: > >>When definiing the macro, you can't/don't prefix the name of the parameter >>with &. Use this: >> >>%macro doit(source); >> >>Within the macro itself, where you have &mydata, you should have &source >>instead. >> >>s/KAM >> >> >>----- Original Message ----- >>From: "SAS user" <Sasuser4@GOOGLEMAIL.COM> >>To: <SAS-L@LISTSERV.UGA.EDU> >>Sent: Sunday, March 14, 2010 05:51 >>Subject: Re: Macro >> >> >>>I used the following code and get the following error >>> %MACRO Doit(&source);:Invalid macro parameter name &. It should be a >>> valid SAS identifier no longer than 32characters. >>> ERROR: A dummy macro will be compiled. >>> >>> >>> and the following WARNING: (%doit(mydata)Apparent invocation of macro > DOIT >>> not resolved. >>> >>> ERROR 180-322: Statement is not valid or it is used out of proper order. >>> >>> Any help will be greatly appreciated. >>> >>> %MACRO Doit(&source); >>> >>> proc sort data= &mydata ;**** change here; >>> by lpermno; >>> run; >>> >>> data fill / view=fill; >>> do until (last.lpermno); >>> set &mydata ;*** change here; >>> by lpermno; >>> if first.lpermno then firstq=4*input(datafqtr,4.)+input(substr >>> (datafqtr,6,1),1.)-1; >>> end; >>> lastq=4*input(datafqtr,4.)+input(substr(datafqtr,6,1),1.)-1; >>> do q=firstq to lastq; >>> datafqtr=put(int(q/4),4.)||'Q'||put(mod(q,4)+1,1.); >>> output; >>> end; >>> keep lpermno datafqtr; >>> run; >>> >>> proc sort data= mydata; >>> by lpermno datafqtr; >>> run; >>> >>> data mydata2; >>> merge &mydata;** change here; >>> by lpermno datafqtr; >>> lagatq=lag(atq); >>> if first.lpermno then lagatq=.; >>> put lpermno datafqtr (atq lagatq) (4.); >>> run; >>> >>> %mend DOIT; >>> >>> %doit(mydata); >>> >


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