BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hugo_B
Obsidian | Level 7

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 .

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

9 REPLIES 9
data_null__
Jade | Level 19

@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.

Hugo_B
Obsidian | Level 7

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.

 

Tom
Super User Tom
Super User

@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"); 
Hugo_B
Obsidian | Level 7

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.

novinosrin
Tourmaline | Level 20

Hello @Hugo_B  Use the below call symputx 

CALL SYMPUTX(CATS ("MV_",&INDEX),'ABCDE','g');

instead of your

CALL SYMPUT(CATS ("MV_",&INDEX),'ABCDE');

 

ChrisLysholm
SAS Employee

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.

 

Astounding
PROC Star

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?

Hugo_B
Obsidian | Level 7
Yes I need it to be deleted at the bottom of the loop, inside the macro program.
Astounding
PROC Star

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 2611 views
  • 5 likes
  • 6 in conversation