Hi everyone,
Can someone explain me why the %SYMDEL in the following code results in the message:
"Warning: Attempt to delete macro variable MV_2 failed. Variable not found."
%MACRO TEST;
%LET INDEX=2;
DATA _NULL_;
CALL SYMPUT(CATS ("MV_",&INDEX),'ABCDE');
RUN;
%PUT MV_&INDEX &MV_2;
%SYMDEL MV_&INDEX;
%SYMDEL MV_2;
%MEND;
%TEST;
And could you tell me if there is a way to delete a Macro variable in a DATA step, the 'reverse' of CALL SYMPUT.
Thank you .
I suppose you could always create it as global:
DATA _NULL_;
CALL SYMPUTX(CATS ("MV_",&INDEX),'ABCDE', 'GLOBAL');
RUN;
Once it's global, %SYMDEL will work.
@Hugo_B wrote:
Hi everyone,
Can someone explain me why the %SYMDEL in the following code results in the message:
"Warning: Attempt to delete macro variable MV_2 failed. Variable not found."
%MACRO TEST; %LET INDEX=2; DATA _NULL_; CALL SYMPUT(CATS ("MV_",&INDEX),'ABCDE'); RUN; %PUT MV_&INDEX &MV_2; %SYMDEL MV_&INDEX; %SYMDEL MV_2; %MEND; %TEST;And could you tell me if there is a way to delete a Macro variable in a DATA step, the 'reverse' of CALL SYMPUT.
Thank you .
According to the documentation SYMDEL deletes symbols from the GLOBAL symbol table. MV_2 is not global in your macro.
CALL SYMDEL is the data equivalent.
RTM.
Thank you very much.
How can I use the macro variable "Index" in the CALL SYMDEL Statement
%LET INDEX=2;
CALL SYMPUT(CATS("MV_",&INDEX),'ABCD'); working.
CALL SYMDEL (MV_&INDEX); not working.
@Hugo_B wrote:
Thank you very much.
How can I use the macro variable "Index" in the CALL SYMDEL Statement
%LET INDEX=2;
CALL SYMPUT(CATS("MV_",&INDEX),'ABCD'); working.
CALL SYMDEL (MV_&INDEX); not working.
What does the dataset variable named MV_2 contain? Does it have the name of the macro you want to delete?
Perhaps you meant.
CALL SYMDEL ("MV_&INDEX");
Actually I am building a macro program performing a loop, the program create a macro variable INDEX, this macro variable is used to build an other macro Variable DAY_&INDEX, I need the Macro Variable DAY_&INDEX to be deleted at the end of the loop;
I might probably set to empty : %LET DAY_&INDEX=; instead of deleting it.
Thank you for your help.
Hello @Hugo_B Use the below call symputx
CALL SYMPUTX(CATS ("MV_",&INDEX),'ABCDE','g');
instead of your
CALL SYMPUT(CATS ("MV_",&INDEX),'ABCDE');
You received an answer for this one, but as an addendum, adding the statement: %PUT _ALL_; as last line in your sample code will result in displaying all GLOBAL (globally scoped) macro variables in global symbol table. This statement would also reveal AUTOMATIC macro variables that automatically exist within the SAS session. That statement would help you debug macro scoping issues.
You haven't shown your looping logic, but you may not need to do anything. As soon as %TEST finishes executing, &MV_2 is automatically deleted. Do you need it deleted sooner than that?
I suppose you could always create it as global:
DATA _NULL_;
CALL SYMPUTX(CATS ("MV_",&INDEX),'ABCDE', 'GLOBAL');
RUN;
Once it's global, %SYMDEL will work.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.