<?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: Create a quoted list separated by commas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876845#M346397</link>
    <description>&lt;P&gt;Thank you very much. Both the solutions worked for me. Now, I understand how to achieve this in the data step.&lt;/P&gt;&lt;P&gt;I didn't understand why ';' and ||';' in catx, but without using these also, it worked. Can you please help me understand why to use ';' and ||';' in catx.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you said though both with or without commas are treated as same, but I want to learn how to do this.&lt;/P&gt;</description>
    <pubDate>Mon, 22 May 2023 06:04:36 GMT</pubDate>
    <dc:creator>Moksha</dc:creator>
    <dc:date>2023-05-22T06:04:36Z</dc:date>
    <item>
      <title>Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876810#M346377</link>
      <description>&lt;P&gt;Hi All, below is the code to create a quoted list separated by spaces. I am trying to modify the program using translate function to create a new list in the same code which contains the output is a list separated by commas. But, what I am trying is not working.&lt;/P&gt;&lt;P&gt;Please, help me how to correct this error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Here, is the code that creates a quoted list separated by spaces:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;data one; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;input empl $;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;12345&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;67890&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;45678&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;%let list=; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;set one; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;call symputx('mac',quote(strip(empl)));&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;call execute('%let list=&amp;amp;list &amp;amp;mac'); &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;run;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;%put &amp;amp;=list;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;Output in the log:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;%put &amp;amp;=list;&lt;BR /&gt;LIST="12345" "67890" "45678"&lt;BR /&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;Now, I am trying to use this LIST in the same program to create a new list separated by commas . Here, is the code that I am trying:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;%let list=;&lt;BR /&gt;%let var1=;&lt;BR /&gt;data _null_;&lt;BR /&gt;set one;&lt;BR /&gt;call symputx('mac',quote(strip(empl)));&lt;BR /&gt;call execute('%let list=&amp;amp;list &amp;amp;mac');&lt;BR /&gt;call execute('%let var1=$sysfunc(translate(&amp;amp;list,',',' '))');&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;=list;&lt;BR /&gt;%put &amp;amp;=var1;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;In the log errors are:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;59 call execute('%let var1=$sysfunc(translate(&amp;amp;list,',',' '))');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;----&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;22&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;-------&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;253&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;||, ~=.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR 253-185: The EXECUTE subroutine call has too many arguments.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;60 run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;NOTE: DATA statement used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;real time 0.01 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;cpu time 0.00 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;61&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;62 %put &amp;amp;=list;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;LIST=&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;63 %put &amp;amp;=var1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;VAR1=&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 May 2023 17:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876810#M346377</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-21T17:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876811#M346378</link>
      <description>&lt;P&gt;A macro function (like SYSFUNC) needs to be called with %, not with $.&lt;/P&gt;
&lt;P&gt;But you can achieve your requested result much easier:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select quote(strip(empl)) into :mac separated by ","
from one;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 May 2023 17:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876811#M346378</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-21T17:40:48Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876812#M346379</link>
      <description>&lt;P&gt;We need the ENTIRE log, not just the errors. This has been mentioned to you before.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, we need this log pasted into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 21 May 2023 17:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876812#M346379</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-21T17:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876813#M346380</link>
      <description>&lt;P&gt;You can skip the CALL SYMPUTX() function in your first code since you don't seem to need that second macro variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=;
data _null_;
  set one;
  call execute(catx(' ','%let list=&amp;amp;list', quote(trim(empl)),';'));
run;

%put &amp;amp;=list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to add commas you need to treat the first one differently than the second one to avoid adding a comma at the front.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set one;
  if _n_=1 then call symputx('list',quote(trim(empl)));
  else call execute(catx(',','%let list=&amp;amp;list', quote(trim(empl)) )||';');
run;

%put &amp;amp;=list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why do you want to add the commas?&amp;nbsp; The IN operator in SAS code does not need them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To SAS these two statements are the same:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where empl in ('1234' '3456');
where empl in ('1234','3456');
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 May 2023 17:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876813#M346380</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-21T17:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876844#M346396</link>
      <description>&lt;P&gt;Thank you very much. It worked for me.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 05:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876844#M346396</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-22T05:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876845#M346397</link>
      <description>&lt;P&gt;Thank you very much. Both the solutions worked for me. Now, I understand how to achieve this in the data step.&lt;/P&gt;&lt;P&gt;I didn't understand why ';' and ||';' in catx, but without using these also, it worked. Can you please help me understand why to use ';' and ||';' in catx.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you said though both with or without commas are treated as same, but I want to learn how to do this.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 06:04:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876845#M346397</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-22T06:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876893#M346407</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439180"&gt;@Moksha&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much. Both the solutions worked for me. Now, I understand how to achieve this in the data step.&lt;/P&gt;
&lt;P&gt;I didn't understand why ';' and ||';' in catx, but without using these also, it worked. Can you please help me understand why to use ';' and ||';' in catx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you said though both with or without commas are treated as same, but I want to learn how to do this.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Must be some "feature" of CALL EXECUTE() when you only send it macro code.&amp;nbsp; Notice how you should have a NOTE in the log that call execute worked but no SAS code was generated.&amp;nbsp; I wouldn't count on it working that way in the future as it seems like a BUG to me.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 13:05:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876893#M346407</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-22T13:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Create a quoted list separated by commas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876897#M346409</link>
      <description>&lt;P&gt;Probably, a bug. Yes, there is a&amp;nbsp;&lt;SPAN&gt;NOTE in the log that call execute worked but no SAS code was generated.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2023 13:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-quoted-list-separated-by-commas/m-p/876897#M346409</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-22T13:15:29Z</dc:date>
    </item>
  </channel>
</rss>

