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.

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
  • 5 replies
  • 912 views
  • 0 likes
  • 3 in conversation