DATA Step, Macro, Functions and more

how to pass all the values of a table to a macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 84
Accepted Solution

how to pass all the values of a table to a macro

i have a macro it will take input as a country and will give its population.

Then i have another table list of all countries. I want to pass all these countries to that macro.

I tried below way i declared all the countries in a global variable and passed that variable

% let countries=india nepal......;

This is not a efficient way. how can i pass all the values of another table in to that macro. Please throw some inputs.


Accepted Solutions
Solution
‎12-14-2014 08:06 AM
Super User
Posts: 10,018

Re: how to pass all the values of a table to a macro

Yeah.

%macro mymac(a);

proc print data=test;

where name = "&a";

run;

%mend;

View solution in original post


All Replies
Super User
Posts: 10,018

Re: how to pass all the values of a table to a macro

proc sort data=have(keep=country) out=country nodupkey;by country;run;

data _null_;

set country;

call execute('%mymacro(country=' ||country|| ')' );

run;

Xia Keshan

Frequent Contributor
Posts: 84

Re: how to pass all the values of a table to a macro

Thanks for your reply Xia Keshan,


I am getting one error. Is there anything i am missing in below code?

data test;

set sashelp.class;

run;

data name_list;

input names$;

cards;

Alfred

Henry

John

Ronald

run;

%macro mymac(a);

proc print data=test;

where name = &a;

run;

%mend;

data _null_;

set name_list;

call execute('%mymac('||names||')');

run;

Solution
‎12-14-2014 08:06 AM
Super User
Posts: 10,018

Re: how to pass all the values of a table to a macro

Yeah.

%macro mymac(a);

proc print data=test;

where name = "&a";

run;

%mend;

🔒 This topic is solved and locked.

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

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