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

Hi,

 

I need to reset the global macro value before the next loop.

 

I am calling macro %dqcreadin which has macro variable: &variables (list of variables like ="&dsn.BLFL &dsn.ORRES"), &domain: list of datasets (e.g. LB#EG).

 

%dqcreadin;
%if %symexist(domain) %then %do;
%do i= 1 %to %eval(%sysfunc(count(&domain,#))+1);
%let dsn=%scan(&domain,&i,#);

 

When next loop starts for new dataset e.g. here EG: &variables should have values EGBLFL EGORRES. However, in my log it has values of previous loop that is LBBLFL LBORRES.

 

I tried using "%symdel  Variables" in program before calling %dqcreadin. However, it still does have LBBLFL LBORRES.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Be advised that frequent use of the program structure like this:

data dqcout;
    set dqcout ;

Can lead to difficult debugging as destroy the original data set. So when attempting to trace back to values of things manipulated (such as your variable var6 / variables ). Especially since you just read an external file in this case AND manipulated the value of the problematic variable in general.

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Show us the code for %dqcreadin, and show us the main code where the macro is called.

--
Paige Miller
petlove
Obsidian | Level 7

%macro dqcreadin(id=);

%xls2sas(_infile=dqc.xlsx, _indir=../../../../../metadata, _sheet=Sheet1, _datarow=2, _outdata=dqcout);

data dqcout;
set dqcout(rename=(var1=id var3=title var6=variables var7=domain var8=issue var10=exception));
if issue='Yes';
if id="&id";
domain=tranwrd(domain,', ','#');
if index(variables,'--')>0 then variables=tranwrd(variables,'--',"&dsn.");
variables=tranwrd(variables,', ',' ');
dmvars =tranwrd(exception,',',' ');
keep id title variables domain issue dmvars ;
run;

%global id title variables domain dmvars;

proc sql;
select id, title , variables, domain, dmvars into :id, :title , :variables, :domain, :dmvars
from dqcout
;
quit;

%put &id &title &variables &domain &dmvars;

%mend dqcreadin;

 

Main code:

 

%macro missblfl;

%symdel variables;
%dqcreadin(id=0021);
%if %symexist(domain) %then %do;
%do i= 1 %to %eval(%sysfunc(count(&domain,#))+1);
%let dsn=%scan(&domain,&i,#);

%if %sysfunc(exist(&sdtm..&dsn)) %then %do;


data &dsn;
set &sdtm..&dsn (keep=usubjid &variables);
record=_n_;
run;

%end;

%end;

%end;

%mend;

%missblfl;

 

ballardw
Super User

Be advised that frequent use of the program structure like this:

data dqcout;
    set dqcout ;

Can lead to difficult debugging as destroy the original data set. So when attempting to trace back to values of things manipulated (such as your variable var6 / variables ). Especially since you just read an external file in this case AND manipulated the value of the problematic variable in general.

 

petlove
Obsidian | Level 7
Thank you for advise. Will follow it.
petlove
Obsidian | Level 7

I changed VARIABLE name in %dqcreadin macro. It resolved the issue. Now, it resets the &variables values for each loop.

 

Thank you for your help and suggestions.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1581 views
  • 0 likes
  • 3 in conversation