<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498671#M132580</link>
    <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;It is not working.I get error 49&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name
into :names separated by '","'
from name_list
where substr(name,1,1) = 'P';
quit;
%put &amp;amp;names;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Sep 2018 09:00:47 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-09-25T09:00:47Z</dc:date>
    <item>
      <title>The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498665#M132576</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;In this example I created a macro variable that get value &amp;nbsp;Peter,Paul&lt;/P&gt;&lt;P&gt;My question is how to modify the code to get values "peter","Paul"&lt;/P&gt;&lt;P&gt;The reason is that I want to use where clause&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data name_list;
length name $10;
Input name $;
datalines;
Peter
John
Paul
David
;
run;


proc sql noprint;
select name
into :names separated by ',' 
from name_list
where substr(name,1,1) = 'P';
quit;
%put &amp;amp;names;
/*Peter,Paul*/



data output;
set name_list;
where name in ("&amp;amp;names");
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 08:15:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498665#M132576</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-25T08:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498666#M132577</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;into :names separated by '","'&lt;BR /&gt;...&lt;BR /&gt;where name in ("&amp;amp;names."); &lt;BR /&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However you really do not need to do this.&amp;nbsp; Simply use a sub-query, it is far easier to program with, and expandable beyond the realms of macro language:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table name_list as
  select *
  from   name_list
  where  name in (select name from name_list where substr(name,1,1)="P");
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;In fact, (and without seeinig the rest of the process), you will most likely be better off creating flags in your data, and just putting where's in where necessary, but can't really tell as only seeing one small part.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 08:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498666#M132577</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-25T08:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498670#M132579</link>
      <description>&lt;P&gt;No need for the macro variable, it's best done in SQL with a sub-select:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table output as select *
from name_list
where name in (select name from name_list where substr(name,1,1) = 'P');
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Of course, since it's all from one table, it can be made still simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output;
set name_list;
where substr(name,1,1) = 'P';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 08:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498670#M132579</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-25T08:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498671#M132580</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;It is not working.I get error 49&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name
into :names separated by '","'
from name_list
where substr(name,1,1) = 'P';
quit;
%put &amp;amp;names;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 09:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498671#M132580</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-09-25T09:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498672#M132581</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select quote(name)
into :names separated by ','
from name_list
where substr(name,1,1) = 'P';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But, to repeat for the x-th time, it's not necessary at all.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 09:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498672#M132581</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-25T09:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498674#M132582</link>
      <description>&lt;P&gt;What would you use in a data-step to add quotes to a string? Using the functions quote and trim in the select-clause solves the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select quote(trim(Name))
      into :names separated by ','
      from name_List
         where Name like 'P%'
   ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you need to modify the last step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data output;
  set name_list;
  where name in (&amp;amp;names.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Sep 2018 09:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498674#M132582</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-09-25T09:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: The INTO Statement in PROC SQL to Create Macro Variable with multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498677#M132585</link>
      <description>&lt;P&gt;I do not get any error when running:&lt;/P&gt;
&lt;PRE&gt;data name_list;
length name $10;
Input name $;
datalines;
Peter
John
Paul
David
;
run;
proc sql noprint;
select name
into :names separated by '","'
from name_list
where substr(name,1,1) = 'P';
quit;
%put &amp;amp;names;&lt;/PRE&gt;
&lt;P&gt;Post your log in future, as text, I do note know what error 49 is or how you got it.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 09:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-INTO-Statement-in-PROC-SQL-to-Create-Macro-Variable-with/m-p/498677#M132585</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-25T09:10:50Z</dc:date>
    </item>
  </channel>
</rss>

