BookmarkSubscribeRSS Feed
sasuser1000
Calcite | Level 5
Hi,

I am trying to delete the value stored inside a macro variable that I have created inside the following macro . the reason why want to delete the value stored inside adjust_session is because when I=1 , adjust_session get the value of 2, but when I=2 'adjust_session' stay with the same value as when I=1.

%macro ADJUST(NOBSI);

%local i;


%do I=1 %TO &NOBSI;
data _null_; /*rechange to data _NULL_*/
set list1 ;
if id=&i then do;
put new_session=;
call symput('adjust_session',new_session);
end;
stop;
run;
.......ETC
%symdel adjust_session y product;
%end;
%mend;
%adjust(&nobsi)

LOG

MLOGIC(ADJUST): %SYMDEL ADJUST_SESSION

WARNING: Attempt to delete macro variable ADJUST_SESSION failed. Variable not found.
6 REPLIES 6
ASASProgrammer
Calcite | Level 5
%SYMDEL is only to delete global variables.
No need to delete local macro variables, since they are removed automatically when macro ends.
sasuser1000
Calcite | Level 5
Hi,

so why the value of 'adjust_session' will not change when I=2 and takes the value of new_session as whenI=1. I know that I is not the problem since I change in my output from 1 to 2 , but adjust_session will have always the same value as when I=1???

%do I=1 %TO &NOBSI;
data _null_; /*rechange to data _NULL_*/
set list1 ;
if id=&i then do;
put new_session=;
call symput('adjust_session',new_session);
RickM
Fluorite | Level 6
I would try either removing the stop statement or use point in the set statement(and get rid of the if statement). According to the documentation on the STOP statement:

The STOP statement causes SAS to stop processing the current DATA step immediately and resume processing statements after the end of the current DATA step.

It looks like the data step will never get past the first observation.
sasuser1000
Calcite | Level 5
RICKM THANK YOU SOOOO MUCH!
IT WORKED!
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello SASUser1000,

I've made some small changes in your code and it works as expected (at least in my opinion):
[pre]
data list1;
do id=1 to 20;
new_session=id**2;
output;
end;
run;
%macro ADJUST(NOBSI);
%local i adjust_session;
%do I=1 %TO &NOBSI;
data _null_; /*rechange to data _NULL_*/
set list1 ;
if id=&i then do;
put new_session=;
call symputx('adjust_session',new_session);
end;
run;
%end;
%mend;
options mprint mlogic;
%adjust(2)
[/pre]
Sincerely,
SPR
sasuser1000
Calcite | Level 5
Thanks SPR, I will check this.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 3472 views
  • 0 likes
  • 4 in conversation