%macro xy;
%array &trt(60) ;
%do i = 1 %to 60;
%symdel trt(i) ;
%end;
%mend xy;
%xy;macro
WARNING: Apparent invocation of macro ARRAY not resolved.
WARNING: Apparent symbolic reference TRT not resolved
i have created trt1 to trt60 macro variables , i want to delete them all at once . can anybody suggest me the way and what mistake i did in this program.?
This doesn't require a macro.
Hi,
I think it quite simple by using %DO Loop...
%macro delete_var;
%do i = 1 %to 60;
%global trt&i.;
%let trt&i = 1;
%symdel trt&i.;
%end;
%mend;
%delete_var
There is no macro equivalent of the data step ARRAY statement.
If you have a numbered series of macro variables that you want to delete then just use a %DO loop.
%do i=1 %to 60;
%if %symexist(trt&i) %then %symdel trt&i ;
%end;
Why do you feel a need to delete the macro variables?
Hi Tom,
I think Chaitanya is trying to make his code more efficient by deleting global macro variables as they are not needed for further processing...
Chaitanya - if your aim is to make your programme more efficient then, rather than delete macro variables, you can assign the macro variables a NULL value like this %let trt1 = ;
By this way, you can save the space that is needed to store global macro variables in global symbol table...
-Urvish
This doesn't require a macro.
I agree with Data_Null_:
a macro is not required, just a subroutine.
Save that solution in a utility file
and whenever you want to do housecleaning
just
%include SiteIncl(symdel_all_global);
here are some points for future reference:
* symdel works on global macro variables
* opinion: it is Very BAD programming practice to write a macro that removes mvars from the global symbol table
* macro array?
I have written three versions:
http://www.sascommunity.org/wiki/Category:Macros_by_Ron_Fehd
which I have deprecated in favor of either of
http://www.sascommunity.org/wiki/Macro_CallMacr
or
http://www.sascommunity.org/wiki/Macro_CallText
or
http://www.sascommunity.org/wiki/Macro_Loops_with_Dates
reference:
http://www.sascommunity.org/wiki/List_Processing_Basics_Creating_and_Using_Lists_of_Macro_Variables
Ron Fehd deprecated(%array) maven
%do loop is also deleting all the macro variables , is there any rationale in using subroutine?
My reframe of your Q is:
I have to write a macro whose only purpose is to do one thing, once.
and my answer is:
Macros are all about repetition.
So, yes, your macro does have one of my two criteria for writing a macro
1. %do
2. %if
but saving and finding a reusable subroutine
is as much work as saving and finding a non-reusable macro
so my vote is for the reusable subroutine.
And,
why are you creating an array of global macro variables in the first place?
They can be %local within the macro that creates and uses them
and are discarded when the macro finishes.
The context of your Q is
-- in my opinion --
not good programming practice.
Ron Fehd better==less maven
got your point..thanks for d clarification..
Here is a one.step solution:
http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0605D&L=sas-l&P=R4163
Ron Fehd SAS-L archives maven
If you say so.
Seems more complex to create more macro variables just so you can say it is one step which its not.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.