BookmarkSubscribeRSS Feed
Rohit12
Obsidian | Level 7

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 

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Rohit12
Obsidian | Level 7
I cannot post the code of macro find as it is company specific macro
Kurt_Bremser
Super User

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

Patrick
Opal | Level 21

@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;
Satish_Parida
Lapis Lazuli | Level 10

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.;
ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 7 replies
  • 874 views
  • 0 likes
  • 6 in conversation