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
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;
"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)
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.
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;
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.;
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.
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.
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.