BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8
%let  A ='India','USA','UK','AUSTRALIA';

how to using macro variable A in proc sql

9 REPLIES 9
rudfaden
Lapis Lazuli | Level 10
proc sql;
select *
from mytable
where country in(&A)

 

pavank
Quartz | Level 8
from mytable means i donot have any table just i have macro variable A only
andreas_lds
Jade | Level 19

@pavank wrote:
from mytable means i donot have any table just i have macro variable A only

And what do you want to with that variable?

The where statement is the place a variable defined like A is used. (quoted strings, comma between values).

rudfaden
Lapis Lazuli | Level 10
What are you trying to achive?
PaigeMiller
Diamond | Level 26

@pavank wrote:
%let  A ='India','USA','UK','AUSTRALIA';

how to using macro variable A in proc sql


As in your last thread, we need you to explain a lot more about what you want. No one understands what you want, and by making your explanation one partial sentence, you are not helping yourself or us. To better help us help you, please EXPLAIN the entire problem with sufficient detail taht we know exactly what you want.

--
Paige Miller
pavank
Quartz | Level 8

how to pass list values in proc sql 

 

%let A ='India',  'USA',    'UK',    'AUSTRALIA'  ;

PaigeMiller
Diamond | Level 26

@pavank wrote:

how to pass list values in proc sql 

 

%let A ='India',  'USA',    'UK',    'AUSTRALIA'  ;


to achieve what outcome from PROC SQL???

 

Please, @pavank , show us the code you want without macro variables, in other words show us the code you want with 'India','USA', etc. hard-coded, and then it should be easy to take that code and make use of &A.

--
Paige Miller
Tom
Super User Tom
Super User

@pavank wrote:

how to pass list values in proc sql 

 

%let A ='India',  'USA',    'UK',    'AUSTRALIA'  ;


Where do you want to PASS it to?

 

Let's forget about SQL for now and just work with normal SAS code.

 

Do you want store that string in a variable?  Add double quotes around it.

data want;
   mylist= "&a";
run;

Do you want to store each quoted word as a value of a variable in a separate observation?

data want;
  length country $20;
  do country=&a ;
    output;
  end;
run;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1658 views
  • 0 likes
  • 6 in conversation