DATA Step, Macro, Functions and more

call a macro through datatep

Reply
Contributor
Posts: 47

call a macro through datatep

data new;
input x;
datalines;
t1
T2
T3
T4
T5
T6
;
RUN;

 

I am having a macro called find .In this macro if I have pass T1 it gives me full table name

for ex

%find(t1)

output will be a dataset called table_desc with one variable table_name have value cust_dept for input t

 

 

I want to create a new macro called great

%macro great

proc sql noprint;

select count(distinct x) into :total from new

order by x;

quit;

 

proc sql noprint;

select distinct x into :name1- :name&total.from new

order by x;

quit;

data xyz;
set new;
%do i=1 to &total.;
%find(&&name&i.);
tabel=t1;
run;

%mend

 

%great

 

 

my final output of xyz

tabel tabel_name
t1 cust_dept
t2 dept_accunt
t3 accunt_customer
t4 account_new

 

could you please help me how can I acheive this 

Super User
Super User
Posts: 9,227

Re: call a macro through datatep

Post example have data (for each dataset) in a datastep so we have something to work with, and what the output should look like.  

It seems like your problem is a very simple one that needs none of that code simply:

proc sql;
  select  memname,memlabel
  from    sashelp.vtable where memname in (select x from new);
quit;
Super User
Posts: 9,611

Re: call a macro through datatep

Please post the code of macro %find.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 47

Re: call a macro through datatep

Posted in reply to KurtBremser
I cannot post the code of macro find as it is company specific macro
Super User
Posts: 9,611

Re: call a macro through datatep

"Dear doc, I won't tell you where it hurts, but could you give me a diagnosis?"

 

Just mask out the company-specific names and values, what's important is the program structure inside the macro (which statements etc)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 4,568

Re: call a macro through datatep

@Rohit12 

If you can't post something because it's company specific/confidential then try to dummy up some representative code/data.

 

To use a SAS data step and call a macro multiple times, passing in for each iteration of the data step another parameter value:

That's what CALL EXECUTE() is for.

http://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p1blnvlvciwgs9n0zcilud6d6ei9.htm&...

 

Here a code sample

%macro sample(param=);
  data _null_;
    put "Parameter is: &Param";
    stop;
  run;
%mend;


data paramList;
  var='abcd xyz'; output;
  var='xy dd'; output;
run;

data _null_;
  set paramList;
  call execute('%sample(param='||var||');');
run;
Frequent Contributor
Posts: 109

Re: call a macro through datatep

I have created one example macro as you can not share the macro code.

 

Suggestion: Please make sure the table descriptions get appended not replaced on repetitive call of the macro.

 

%macro find(tabname=);
	%put &tabname.;
%mend find;

data tablist;
input tables:$20.;
cards;
account
people
list
transaction
amortization
service
;
run;

proc sql noprint;
select distinct '%find(tabname='||strip(tables)||')' into :runmacro separated by ';' from tablist;
quit;

&runmacro.;
Super User
Posts: 13,084

Re: call a macro through datatep

If your macro %find involves any procedures or calls a data step such as

data _null_;

  <any other code>

run;

 

Then the data step "calling" find will quit as soon as it finds proc or data statement as that is a boundary.

 

Example:

data junk;

   x=3;

proc print data=sashelp.class;

run;

 

the "proc print" tells SAS that the data step Junk is finished.

Ask a Question
Discussion stats
  • 7 replies
  • 99 views
  • 0 likes
  • 6 in conversation