DATA Step, Macro, Functions and more

%let catx call execute

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

%let catx call execute

 

Hello,

 I want to have the list of tables  that do not contain data with this method.
A can't make the "retain" of the macro variable table1
Thank you for your help.

 

%macro tab(mem=);
%global table1 ;
%let table1=;
%local table;
%let table=;
%let dsid  = %sysfunc(open(&mem.,in));
%let nbr   = %sysfunc(attrn(&dsid,nobs));
%if &nbr.=0 %THEN %do; 
%let table =&mem.;
%let table1=%sysfunc(catx('-',&table,&table1));
%end;
%if &dsid. > 0 %then 


%let rc = %sysfunc(close(&dsid)); %mend tab; DATA _null_; SET vcol; call execute('%tab(mem='||strip(memname)||');'); run; %Put table1=&table1;

 


Accepted Solutions
Solution
‎04-04-2018 09:01 AM
Super Contributor
Posts: 500

Re: %let catx call execute

Posted in reply to mansour_ibrahim

unable to add the missing code to my last post, so here it is:

 

proc sql noprint;
   select MemName
      into :table1 separated by '-'
      from sashelp.vtable
         where nobs = 0 and MemName in (
            select MemName from work.vcol
         )
   ;
quit;

%put &=table1;

View solution in original post


All Replies
Super User
Posts: 9,611

Re: %let catx call execute

Posted in reply to mansour_ibrahim
  1. why not retrieve the nobs from dictionary.tables?
  2. do this 
    %let table1=&table.-&table1;
     instead of
    %let table1=%sysfunc(catx('-',&table,&table1));
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super Contributor
Posts: 500

Re: %let catx call execute

[ Edited ]
Posted in reply to mansour_ibrahim

You reset &table1 each time the macro is called

%let table1=;

To solve this remove

%global table1 ;
%let table1=;

 from the macro and put them before the data-step.

 

Even better: use dictionary.tables, as suggested by @KurtBremser.

 

The following code is untested, because i don't know what you have in dataset "vcol":

 

Solution
‎04-04-2018 09:01 AM
Super Contributor
Posts: 500

Re: %let catx call execute

Posted in reply to mansour_ibrahim

unable to add the missing code to my last post, so here it is:

 

proc sql noprint;
   select MemName
      into :table1 separated by '-'
      from sashelp.vtable
         where nobs = 0 and MemName in (
            select MemName from work.vcol
         )
   ;
quit;

%put &=table1;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 115 views
  • 2 likes
  • 3 in conversation