From: Rune Runnest? on 10 Jan 2006 07:47 The %symdel statement can be used to delete macro variables from the global symbol table. Here is a piece of code you probably can submit, I guess the table sasuser.courses is a part of the SAS release. proc copy in = sasuser out = work; select courses; run; options symbolgen mprint mlogic; %macro printdsn; %global dsn vars; %let dsn=work.courses; %let vars=course_title course_code days; %put &dsn; proc print data=&dsn; var &vars; title "Listing of &dsn data set"; run; %mend; %put &dsn; %printdsn %symdel dsn; %printdsn; *Why does this macro call work now - cause it does ?! ; Partial output from the log: 74 %put &dsn; SYMBOLGEN: Macro variable DSN resolves to work.courses work.courses 75 %symdel dsn; 76 %put &dsn; WARNING: Apparent symbolic reference DSN not resolved. &dsn How is it that &dsn can be used to call the macro %printdsn after the %symdel statement has removed the macro variable dsn from the global symbol table ? Rune
From: Joep on 10 Jan 2006 07:56 Rune, The macro %printdsn works after removing the macro variable dsn from the global symbol table, because you recreate dsn in the macro printdsn. Regards, Joep
From: toby dunn on 10 Jan 2006 10:20 Rune , Lets break this down: %put &dsn; Will yeild a warning as you havent yet invoked the macro %printdsn.... %printdsn Will run the macro %Printdsn and create two global macro vars 'dsn and vars'. Why do you need global vars here anyways? %symdel dsn; Delete one global macro var 'dsn', again why do you need global macro vars at all here. Good macro design neccessitates that a macro clean up after itself. Hence you will need to put this statement up into your macro %printdsn. %printdsn; This will work simple because the macro needs no external macro var to run. It creates and/or updates a global macro var's that the resulting SAS code needs to run, every time you invoke it. >>How is it that &dsn can be used to call the macro %printdsn after the >>%symdel statement has removed the macro variable dsn from the global >>symbol >>table ? This statement confuses me as &dsn does not and will not as you have the code below written, ever call %printdsn. Toby Dunn From: Rune Runnest? <rune(a)FASTLANE.NO> Reply-To: Rune Runnest? <rune(a)FASTLANE.NO> To: SAS-L(a)LISTSERV.UGA.EDU Subject: deleting macro variables with the %SYMDEL statement Date: Tue, 10 Jan 2006 13:47:02 +0100 The %symdel statement can be used to delete macro variables from the global symbol table. Here is a piece of code you probably can submit, I guess the table sasuser.courses is a part of the SAS release. proc copy in = sasuser out = work; select courses; run; options symbolgen mprint mlogic; %macro printdsn; %global dsn vars; %let dsn=work.courses; %let vars=course_title course_code days; %put &dsn; proc print data=&dsn; var &vars; title "Listing of &dsn data set"; run; %mend; %put &dsn; %printdsn %symdel dsn; %printdsn; *Why does this macro call work now - cause it does ?! ; Partial output from the log: 74 %put &dsn; SYMBOLGEN: Macro variable DSN resolves to work.courses work.courses 75 %symdel dsn; 76 %put &dsn; WARNING: Apparent symbolic reference DSN not resolved. &dsn How is it that &dsn can be used to call the macro %printdsn after the %symdel statement has removed the macro variable dsn from the global symbol table ? Rune
From: David L Cassell on 10 Jan 2006 14:33 rune(a)FASTLANE.NO wrote: >The %symdel statement can be used to delete macro variables from the global >symbol table. Yes. And if you have to use it to delete global variables, then you *may* be making mistakes in your process design. I recommend that you *not* use global variables at all, until you absolutely have to. Go with local macro variables. Or don't use macro variables at all. >Here is a piece of code you probably can submit, I guess the table >sasuser.courses is a part of the SAS release. > > proc copy in = sasuser out = work; > select courses; > run; > options symbolgen mprint mlogic; > > %macro printdsn; > %global dsn vars; There is no reason you couldn't use %LOCAL here instead. And you wouldn't have to use %SYMDEL afterward. > %let dsn=work.courses; > %let vars=course_title course_code days; > %put &dsn; > proc print data=&dsn; > var &vars; > title "Listing of &dsn data set"; > run; > %mend; Okay, I realize that this is just an example program. But it could be a lot better if you put your macro variables in a local scope, and you had named parameters, and you created the macro variables in a way that would be more flexible than %LET statements that are fixed in stone. > %put &dsn; > > %printdsn > > %symdel dsn; > >%printdsn; *Why does this macro call work now - cause it does ?! ; You're forgetting. You have MPRINT going. Surely your log explains it. You are creating your macro variables once again. Your macro creates them anew everytime. >Partial output from the log: > >74 %put &dsn; >SYMBOLGEN: Macro variable DSN resolves to work.courses >work.courses >75 %symdel dsn; >76 %put &dsn; >WARNING: Apparent symbolic reference DSN not resolved. >&dsn > >How is it that &dsn can be used to call the macro %printdsn after the >%symdel statement has removed the macro variable dsn from the global symbol >table ? It isn't. Well, you wipe it out of the global symbol table. But then, you build it again as soon as you run %PRINTDSN again. Try a %put &dsn; right after that latest %PRINTDSN and you'll see that you have instantiated the macro variable once again. So try it with macro variables that only have local scope, and you'll see that the system cleans up those variables for you when you leave the scope. HTH, David -- David L. Cassell mathematical statistician Design Pathways 3115 NW Norwood Pl. Corvallis OR 97330 _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
|
Pages: 1 Prev: SAS Dates Next: Is There a Procedure Like "PROC SURVEYCORR"? |