<?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: Adding Single Quote to list of strings in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302606#M60735</link>
    <description>&lt;P&gt;Do it in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set col_code end=done;
length collist $1000; * set sufficient length here;
retain collist;
collist = catx(',',"'"!!col_code!!"'",trim(collist));
if done then call symput('collist',trim(collist));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 05 Oct 2016 12:36:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-10-05T12:36:40Z</dc:date>
    <item>
      <title>Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302599#M60733</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am stuck with a small issue in PROC SQL. I have to fetch from a flat file &amp;amp; use that string in a sql query but the items in the list are strings so during the fetch i need to fetch it with quotes to use it in oracle. Any Help would be much appretiated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CODE.txt&lt;BR /&gt;AAA&lt;BR /&gt;AAB&lt;BR /&gt;AAC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename colcode "/xyz/CODE.txt";run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data col_code;&lt;BR /&gt;infile colcode;&lt;BR /&gt;length col_code $3.;&lt;BR /&gt;input col_code $;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select (trim(left(col_code))) into:collist separated by ', '&lt;/P&gt;&lt;P&gt;from col_code;run;&lt;BR /&gt;%put Colleage LIST IS: &amp;amp;collist ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current Output:-&lt;/P&gt;&lt;P&gt;Colleage LIST IS: AAA, AAB, AAC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Required Output:-&lt;/P&gt;&lt;P&gt;Colleage LIST IS: 'AAA', 'AAB', 'AAC'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using that &amp;amp;collist in a where condition in one sql run on oracle in later stages.!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302599#M60733</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-10-05T12:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302604#M60734</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do the following&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;select " ' "||STRIP(col_code)||" ' " into:collist separated by ', '&lt;/P&gt;
&lt;P&gt;from col_code;run;&lt;BR /&gt;%put Colleage LIST IS: %superq(collist);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your Oracle query, use %unquote(&amp;amp;collist)&amp;nbsp; /* &amp;lt;--- This avoids getting SAS Macro compiler errors, yet preserves the single quotes around each value */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302604#M60734</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2016-10-05T12:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302606#M60735</link>
      <description>&lt;P&gt;Do it in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set col_code end=done;
length collist $1000; * set sufficient length here;
retain collist;
collist = catx(',',"'"!!col_code!!"'",trim(collist));
if done then call symput('collist',trim(collist));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:36:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302606#M60735</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-10-05T12:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302607#M60736</link>
      <description>Here is another quick way.&lt;BR /&gt;1. Add the following to your existing code&lt;BR /&gt;%let collist = %sysfunc(tranwrd(%superq(collist)),%str(,),%str(%', %')));&lt;BR /&gt;%put Colleage LIST IS: %superq(collist) ;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302607#M60736</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2016-10-05T12:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302609#M60737</link>
      <description>&lt;P&gt;Thanks ahmed for the reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only trouble with this approach was&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Colleage LIST IS: ' AAA ', ' AAB ', ' AAC ' // there were spaces in between.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302609#M60737</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-10-05T12:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302612#M60738</link>
      <description>&lt;P&gt;Thanks a lot! Saved my day &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302612#M60738</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-10-05T12:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302616#M60739</link>
      <description>&lt;P&gt;QUOTE() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p059exu866hqw2n0zw9aoxf3p6oj.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p059exu866hqw2n0zw9aoxf3p6oj.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc SQL noprint;&lt;/P&gt;
&lt;P&gt;select quote(name, "'") into :name_list separated by ","&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from sashelp.class;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;name_list;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 12:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302616#M60739</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-05T12:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302623#M60740</link>
      <description>&lt;P&gt;A word of advice. &amp;nbsp;Using lists of data in macro language will almost always result in over complicated, hard to maintain or read code and processing. &amp;nbsp;Adding in quotation marks will really make your code even harder. &amp;nbsp;Also, in almost all cases there is not a need to do this at all anyways. &amp;nbsp;Simply changing the strcuture of the data or processing in a different manner results in far simpler code.&lt;/P&gt;
&lt;P&gt;Now, you say you are using that macro variable in an SQL where clause later on, if so then just simply subquery the dataset in that where clause to avoid all this totally:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select *
  from   HAVE
  where  ID in (select distinct COL_CODE from COL_CODE);
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 13:02:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302623#M60740</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-10-05T13:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302624#M60741</link>
      <description>&lt;P&gt;Thanks a lot. &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 13:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302624#M60741</guid>
      <dc:creator>GunnerEP</dc:creator>
      <dc:date>2016-10-05T13:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302633#M60742</link>
      <description>&lt;P&gt;The space " ' " was left for code clarity purposes! otherwise it would have looked like this "'"!!&lt;/P&gt;
&lt;P&gt;You can incorporate Reeza's quote(name,"'") function use instead in your first sql statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 13:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302633#M60742</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2016-10-05T13:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Single Quote to list of strings</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302784#M60758</link>
      <description>&lt;P&gt;You were almost there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;34         proc sql noprint;
35            select &lt;FONT color="#ff6600"&gt;quote(strip(col_code),"'")&lt;/FONT&gt; into:collist separated by ', '
36            from col_code;
37            quit;
38            run;
39         %put Colleage LIST IS: &amp;amp;=collist ;
Colleage LIST IS: COLLIST='AAA', 'AAB', 'AAC'&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2016 20:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Adding-Single-Quote-to-list-of-strings/m-p/302784#M60758</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-10-05T20:19:22Z</dc:date>
    </item>
  </channel>
</rss>

