<?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: concatenating variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434821#M107952</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;i didi it like below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table one as select distinct sex from sashelp.classfit&lt;BR /&gt;order by sex;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;set one end=eof;&lt;BR /&gt;if eof then&lt;BR /&gt;sex_1 = cat("'",sex,"'");&lt;BR /&gt;else sex_1= cat("'",sex,"'",',');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select sex_1 into: var_list separated by " " from two;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var_list;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Feb 2018 11:56:16 GMT</pubDate>
    <dc:creator>soham_sas</dc:creator>
    <dc:date>2018-02-07T11:56:16Z</dc:date>
    <item>
      <title>concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434620#M107868</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;i have a data set which contains some value&amp;nbsp;(lets say a,b,c&amp;nbsp;e.t.c) , now i have to&amp;nbsp;create a macro for those values and that macro i have to use in a sql like (where name in (&amp;amp;macro)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so i am trying to concatenate the observations by single cotes and a comma but its not working&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example i am trying the sashelp.class&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;HAVE&lt;/TD&gt;&lt;TD&gt;WANT&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;'F',&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;M&lt;/TD&gt;&lt;TD&gt;'M'&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also please note that in the last observation we don't need the comma to be there in the result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table test1 as&lt;BR /&gt;select distinct sex from sashelp.classfit&lt;BR /&gt;order by sex;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;by sex;&lt;BR /&gt;if last.sex = 1 then&lt;BR /&gt;sex1=cat("'",sex,"'"); else&lt;BR /&gt;sex1 = cat("'",sex,"'",",");&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 17:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434620#M107868</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-02-06T17:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434621#M107869</link>
      <description>&lt;P&gt;Use the QUOTE() function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct quote(sex) into :var_list separated by " " from sashelp.class;
quit;

%put &amp;amp;var_list.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;i have a data set which contains some value&amp;nbsp;(lets say a,b,c&amp;nbsp;e.t.c) , now i have to&amp;nbsp;create a macro for those values and that macro i have to use in a sql like (where name in (&amp;amp;macro)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so i am trying to concatenate the observations by single cotes and a comma but its not working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for example i am trying the sashelp.class&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;HAVE&lt;/TD&gt;
&lt;TD&gt;WANT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;F&lt;/TD&gt;
&lt;TD&gt;'F',&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;M&lt;/TD&gt;
&lt;TD&gt;'M'&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;also please note that in the last observation we don't need the comma to be there in the result&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table test1 as&lt;BR /&gt;select distinct sex from sashelp.classfit&lt;BR /&gt;order by sex;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test2;&lt;BR /&gt;set test1;&lt;BR /&gt;by sex;&lt;BR /&gt;if last.sex = 1 then&lt;BR /&gt;sex1=cat("'",sex,"'"); else&lt;BR /&gt;sex1 = cat("'",sex,"'",",");&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 17:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434621#M107869</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-06T17:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434634#M107872</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;thanks for the solutions , but can you please suggest something like i have mentioned in the want column i.e single qoute with comma separated (like 'f','m')&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 18:22:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434634#M107872</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-02-06T18:22:28Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434635#M107873</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;thanks for the solutions , but can you please suggest something like i have mentioned in the want column i.e single qoute with comma separated (like 'f','m')&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How is that different than what I suggested?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRIKE&gt;EDIT: Are you really saying you can't add a &amp;nbsp;comma to the SEPARATED BY portion and look up the QUOTE function to figure out how to use single instead of double quotes and you want me to do it for you?&lt;/STRIKE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT2:&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt;&amp;nbsp;that wasn't an appropriate response. You can modify it by changing the SEPARATED BY portion - right now it's just adding spaces, and look into the QUOTE function to see how to have it generate single quotes instead of double quotes. If you're still having difficulty with this post what you've tried and explain what isn't working.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 22:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434635#M107873</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-06T22:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434668#M107893</link>
      <description>&lt;P&gt;Any takers on a bet that shortly we'll be seeing a "why am I getting a more positional parameters than defined " question?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 19:16:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434668#M107893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-06T19:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434821#M107952</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;i didi it like below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table one as select distinct sex from sashelp.classfit&lt;BR /&gt;order by sex;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;set one end=eof;&lt;BR /&gt;if eof then&lt;BR /&gt;sex_1 = cat("'",sex,"'");&lt;BR /&gt;else sex_1= cat("'",sex,"'",',');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select sex_1 into: var_list separated by " " from two;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;var_list;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 11:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434821#M107952</guid>
      <dc:creator>soham_sas</dc:creator>
      <dc:date>2018-02-07T11:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: concatenating variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434852#M107956</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/93889"&gt;@soham_sas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;i didi it like below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table one as select distinct sex from sashelp.classfit&lt;BR /&gt;order by sex;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;data two;&lt;BR /&gt;set one end=eof;&lt;BR /&gt;if eof then&lt;BR /&gt;sex_1 = cat("'",sex,"'");&lt;BR /&gt;else sex_1= cat("'",sex,"'",',');&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select sex_1 into: var_list separated by " " from two;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;var_list;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you "need" the list in a macro variable, you don't need the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
   select distinct quote(trim(Sex), "'") 
      into :varList separated by ','
      from sashelp.class
   ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 14:04:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenating-variable-names/m-p/434852#M107956</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-02-07T14:04:32Z</dc:date>
    </item>
  </channel>
</rss>

