BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

Hello,

 

I want by using sql (or by other methode)  to create a macro variable like this

v_name ='Bob','alice','Petter'

I have tried sql with

proc sql;

  select  distinct name into :v_name sparated by '',''

    from dbase;

quit;

 

I will get  name= Bob','alice','Petter, but I want to get name= 'Bob','alice','Petter'

Thank you

 

4 REPLIES 4
Reeza
Super User

Use the QUOTE() function and separated by space.

 

proc sql;
  select  distinct quote(name) into :v_name separated by ", "
    from dbase;
quit;
LineMoon
Lapis Lazuli | Level 10

Thank you for your answer.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

What exactly are you going to do with a macro variable which resolves as:

'Bob','alice','Petter'

 

I assume your going to use it in either a do loop or an SQL where.  Might I suggest a better way of doing it for SQL would be to put your parameters in a dataset and use a where (subclause) sytax, e.g:

data params;
  param="Bob"; output;
  param="Alice"; output;
  param="Petter"; output;
run;

proc sql;
  select   * 
  from     HAVE 
  where   NAME in (select PARAM from PARAMS);
quit;
LineMoon
Lapis Lazuli | Level 10

Thank you

sas-innovate-2024.png

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.

 

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
  • 4 replies
  • 827 views
  • 3 likes
  • 3 in conversation