DATA Step, Macro, Functions and more

SAS SQL and into

Reply
Super Contributor
Posts: 371

SAS SQL and into

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

 

Super User
Posts: 19,870

Re: SAS SQL and into

Use the QUOTE() function and separated by space.

 

proc sql;
  select  distinct quote(name) into :v_name separated by ", "
    from dbase;
quit;
Super Contributor
Posts: 371

Re: SAS SQL and into

Thank you for your answer.

 

Super User
Super User
Posts: 7,997

Re: SAS SQL and into

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;
Super Contributor
Posts: 371

Re: SAS SQL and into

Thank you

Ask a Question
Discussion stats
  • 4 replies
  • 208 views
  • 3 likes
  • 3 in conversation