BookmarkSubscribeRSS Feed
shlomiohana
Obsidian | Level 7

Hello,

I wrote the following code:

%macro getTables(saplib=SAPBW,saslib=SAP_TEXT);

options validmemname=extend validvarname=any;
 
data texttbls;
   set sashelp.vtable;
   where libname = "&saplib" and (memname =: "/BI0/T" or memname =: "/BIC/T");
run;

 
data _null_;
   set texttbls;
   call symputx('texttbls',_n_);
   call symputx(catt('saptexttbl',_n_),memname);
   call symputx(catt('sastexttbl',_n_),translate(memname,"_","/"));
run;


%do i = 1 %to &texttbls;
   data &saslib.."&&sastexttbl&i"n;
      set &saplib.."&&saptexttbl&i"n;
   run;

%end;

%mend;

%getTables();

I want the loop not to try to read from the SAPBW library two tables.
Table names: _BI0_TRELOCAT + _BI0_TLVANOFT.
What change should be made to the code?

Thank's.

3 REPLIES 3
Tom
Super User Tom
Super User

So is the actual requirement that you don't want to run the data step when the name is not changing?

 

If so add a WHERE statement to the data step or augment the WHERE condition in the SQL query.

data _null_;
   set texttbls;
   where memname ne translate(memname,"_","/");

Or perhaps just 

data _null_;
   set texttbls;
   where indexc(memname,'/');
ballardw
Super User

Since you have the names of the tables in a data set I would consider using Call Execute instead of creating macro variables.

Then you could test the value of the Memname variable not do the call execute.

 

Dummy code;

data _null_;
   set texttbls;
   if memname not in ("_BIO_TRELOCAT" "_BIO_TLVANOFT") then
       call execute ("build that data step code here");
run;

 

Reeza
Super User

@shlomiohana wrote:

Hello,

I wrote the following code:

%macro getTables(saplib=SAPBW,saslib=SAP_TEXT);
...

%getTables();

I want the loop not to try to read from the SAPBW library two tables.
Table names: _BI0_TRELOCAT + _BI0_TLVANOFT.
What change should be made to the code?

Thank's.

 

You've set the macro at the top to read from the SAPBW library. If you want to change that library you can try to change the macro call. 

%getTables(saplib=newLibraryHERE, saslib=SAP_TEXT);

 

Spoiler

@shlomiohana wrote:

Hello,

I wrote the following code:

%macro getTables(saplib=SAPBW,saslib=SAP_TEXT);

options validmemname=extend validvarname=any;
 
data texttbls;
   set sashelp.vtable;
   where libname = "&saplib" and (memname =: "/BI0/T" or memname =: "/BIC/T");
run;

 
data _null_;
   set texttbls;
   call symputx('texttbls',_n_);
   call symputx(catt('saptexttbl',_n_),memname);
   call symputx(catt('sastexttbl',_n_),translate(memname,"_","/"));
run;


%do i = 1 %to &texttbls;
   data &saslib.."&&sastexttbl&i"n;
      set &saplib.."&&saptexttbl&i"n;
   run;

%end;

%mend;

%getTables();

I want the loop not to try to read from the SAPBW library two tables.
Table names: _BI0_TRELOCAT + _BI0_TLVANOFT.
What change should be made to the code?

Thank's.


 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 286 views
  • 0 likes
  • 4 in conversation