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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.