<?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: comma separated list using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954671#M372831</link>
    <description>&lt;P&gt;You right, the limitation remains, that's why I'm fully support (2x&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;) those ballot ideas you shared. Unfortunately, I'm afraid that SAS (the firm) won't be very eager to add new features to SAS (language and 9 engine)... With all that "Viya-centrism"... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But hopefully Workbench will give more drive to make some good BASE engine extensions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Fri, 27 Dec 2024 07:57:43 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2024-12-27T07:57:43Z</dc:date>
    <item>
      <title>comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954548#M372780</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employees;
    input department $ employee $;
    datalines;
Sales John
Sales Mary
HR Alice
HR Bob
IT Eve
IT Charlie
;
run;


proc sql;
    select department,
           catx(',', employee) as employees
    from
        select distinct department,
               employee
        from employees
    ) group by employee,department;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how to get comma separated employees list for each department using proc sql&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 09:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954548#M372780</guid>
      <dc:creator>pavank</dc:creator>
      <dc:date>2024-12-24T09:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954550#M372782</link>
      <description>&lt;P&gt;There's no such SQL function in SAS sadly.&lt;/P&gt;
&lt;P&gt;See&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/create-string-summary-functions/idi-p/288035" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/create-string-summary-functions/idi-p/288035&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Add-GROUP-CONCAT-function-to-proc-sql/idi-p/323092" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Add-GROUP-CONCAT-function-to-proc-sql/idi-p/323092&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 09:21:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954550#M372782</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-12-24T09:21:42Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954555#M372783</link>
      <description>&lt;P&gt;Please tell us what you would do with these comma separated lists by department, so that we may be able to come up with another method that doesn't involve SQL.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 10:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954555#M372783</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-12-24T10:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954558#M372784</link>
      <description>In SAS, you do this with a DATA step, not with SQL.&lt;BR /&gt;See Maxim 14.</description>
      <pubDate>Tue, 24 Dec 2024 11:47:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954558#M372784</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-24T11:47:24Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954560#M372786</link>
      <description>&lt;P&gt;First remark: Maxim 14: Use the right tool.&lt;/P&gt;
&lt;P&gt;Do it the SAS way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employees;
    input department $ employee $;
    datalines;
Sales John
Sales Mary
HR Alice
HR Bob
IT Eve
IT Charlie
IT Zelda
;
run;

data Want;
  set employees;
  by department notsorted;
  length list $ 100;
  retain list;
  if first.department then list="";

  list = catx(",",list,employee);

  if last.department;
  keep department list;
run;
proc print data=want;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Second remark:&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;: "You can't do it in SAS",&lt;/P&gt;
&lt;P&gt;Me: "Hold my beer" &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Assuming you know the maximum number of employees in a department (and you can count that) you could try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employees;
    input department $ employee $;
    datalines;
Sales John
Sales Mary
HR Alice
HR Bob
IT Eve
IT Charlie
IT Zelda
;
run;

data Want;
  set employees;
  by department notsorted;
  length list $ 100;
  retain list;
  if first.department then list="";

  list = catx(",",list,employee);

  if last.department;
  keep department list;
run;
proc print;
run; 

proc sql;
select max(m)
into :maxDept /* max number of people in a the department */
from
(select count(department) as m 
 from employees
 group by department
)
;

create table wantSQL_base as
  select distinct department, employee, count(employee) as n
  from
  (
    select a.*
    from employees as a
    join employees as b
    on a.department = b.department
    and a.employee&amp;lt;=b.employee
  )
  group by department, employee
;

create table wantSQL_final as
  select distinct  
  t1.department, catx(","
  %macro loop1(n);
    %do n=1 %to &amp;amp;n;
      ,t&amp;amp;n..employee
    %end;
  %mend;
  %loop1(&amp;amp;maxDept.)
  ) as list
  from
    %macro loop2(n);
    %do n=1 %to &amp;amp;n;
      %if &amp;amp;n&amp;gt;1 %then left join;
      (select department, employee from wantSQL_base where n=&amp;amp;n.) as t&amp;amp;n.
      %if &amp;amp;n&amp;gt;1 %then on t&amp;amp;n..department = t%eval(&amp;amp;n.-1).department;
    %end;
    %mend;
    %loop2(&amp;amp;maxDept.)
;
quit;


proc print data=wantSQL_base;
run; 
proc print data=wantSQL_final;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(But remember the fact you CAN do something does not mean you SHOULD do it!)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 12:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954560#M372786</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-12-24T12:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954563#M372787</link>
      <description>&lt;P&gt;I want to suggest a small optimization to your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  set employees;
  by department notsorted;
  length list $ 100;
  retain list;
  if first.department
  then list = employee;
  else list = catx(",",list,employee);
  if last.department;
  keep department list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This way you do only one assignment at FIRST.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 12:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954563#M372787</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-12-24T12:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954564#M372788</link>
      <description>&lt;P&gt;Good point! Thanks Kurt (&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 24 Dec 2024 12:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954564#M372788</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-12-24T12:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954567#M372789</link>
      <description>&lt;P&gt;Here's another just-for-fun approach, suitable (without further additions) only for small examples like your sample data or &lt;FONT face="courier new,courier"&gt;sashelp.class&lt;/FONT&gt;, if any:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select catx(':',department,employee,department) into :x separated by '|'
from employees
order by department, employee;

create table want as
select department, scan(substr(tranwrd("&amp;amp;x",cats(':',department,'|',department,':'),', '),find("&amp;amp;x",cats(department,':'))),2,':') as emp_list
from (select distinct department from employees);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2024 14:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954567#M372789</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-12-24T14:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954581#M372790</link>
      <description>&lt;P&gt;That is not something that SQL is designed to support since it does not look like set operations (or relational algebra).&amp;nbsp; I know that many databases that use SQL as their query language have enhanced the SQL language to handle such things.&amp;nbsp; But that is because they did not already have a data manipulation language, like SAS does.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I note that your posted data is grouped by department already (but not sorted) so you could process it as is by using the NOTSORTED keyword on the BY statement.&amp;nbsp; But you probably want to first SORT by the grouping variable (DEPARTMENT).&amp;nbsp; You might also want to sort within the grouping variable by some other variable that makes sense.&amp;nbsp; Perhaps seniority in the department? Or in the company? Or just alphabetically by name.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will also need to decide how long this new character variable needs to be to hold the longest possible list of employees.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=employees ;
  by department employee;
run;
data want ;
  do until(last.department);
     set employees;
     by department employee;
     length employees $200 ;
     employees = catx(',',employees,employee);
  end;
  keep department employees ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Dec 2024 19:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954581#M372790</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-24T19:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954602#M372801</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;: "You can't do it in SAS",&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I only said SQL can't do it in SAS, not that SAS can't do it.&lt;/P&gt;
&lt;P&gt;You are (cleverly!) supplementing the limitation of SQL by adding a layer of macro language logic, but the limitation remains. &lt;/P&gt;</description>
      <pubDate>Wed, 25 Dec 2024 13:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954602#M372801</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-12-25T13:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954671#M372831</link>
      <description>&lt;P&gt;You right, the limitation remains, that's why I'm fully support (2x&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;) those ballot ideas you shared. Unfortunately, I'm afraid that SAS (the firm) won't be very eager to add new features to SAS (language and 9 engine)... With all that "Viya-centrism"... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But hopefully Workbench will give more drive to make some good BASE engine extensions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 07:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954671#M372831</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-12-27T07:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954992#M372974</link>
      <description>There's also this SQL improvement of you feel like voting more&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Add-window-functions-in-SAS-SQL/idi-p/462556" target="_blank"&gt;https://communities.sas.com/t5/SASware-Ballot-Ideas/Add-window-functions-in-SAS-SQL/idi-p/462556&lt;/A&gt;</description>
      <pubDate>Fri, 03 Jan 2025 04:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/954992#M372974</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2025-01-03T04:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/966596#M376185</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/390518"&gt;@pavank&lt;/a&gt;&amp;nbsp;does this answer your question? My code and result is as follows (the code I take as my reference code is in SAS Macro1: essentials course note pdf):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data employees;
   input department $ employee $;
   datalines;
Sales John
Sales Mary
HR Alice
HR Bob
IT Eve
IT Charlie
;
run;
proc sql;
select distinct department
   into :deptlist1-
   from employees;
quit;
%put &amp;amp;sqlobs;/*3*/
%put &amp;amp;deptlist1 &amp;amp;deptlist2 &amp;amp;deptlist3;
%macro emp;
%do i=1 %to 3;
proc sql noprint;
select distinct employee
   into :emplist separated by ','
   from employees
   where department="&amp;amp;&amp;amp;deptlist&amp;amp;i";
quit;
%put &amp;amp;emplist;
%end;
%mend emp;
%emp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt; 69         data employees;
 70            input department $ employee $;
 71            datalines;
 
 NOTE: The data set WORK.EMPLOYEES has 6 observations and 2 variables.&lt;/PRE&gt;
&lt;DIV id="sasLogNote3_1747327352176" class="sasNote"&gt;
&lt;PRE&gt; 78         ;
 79         run;
 80         proc sql;
 81         select distinct department
 82            into :deptlist1-
 83            from employees;
 84         quit;
 NOTE: PROCEDURE SQL used (Total process time):&lt;/PRE&gt;
&lt;PRE&gt; 85         %put &amp;amp;sqlobs;/*3*/
 3
 86         %put &amp;amp;deptlist1 &amp;amp;deptlist2 &amp;amp;deptlist3;
 HR IT Sales
 87         %macro emp;
 88         %do i=1 %to 3;
 89         proc sql noprint;
 90         select distinct employee
 91            into :emplist separated by ','
 92            from employees
 93            where department="&amp;amp;&amp;amp;deptlist&amp;amp;i";
 94         quit;
 95         %put &amp;amp;emplist;
 96         %end;
 97         %mend emp;
 98         %emp;
 NOTE: PROCEDURE SQL used (Total process time):&lt;/PRE&gt;
&lt;PRE&gt; Alice,Bob
 NOTE: PROCEDURE SQL used (Total process time):&lt;/PRE&gt;
&lt;PRE&gt; Charlie,Eve
 NOTE: PROCEDURE SQL used (Total process time):&lt;/PRE&gt;
&lt;PRE&gt; John,Mary
 99         
 100        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 15 May 2025 16:53:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/966596#M376185</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-15T16:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/966638#M376189</link>
      <description>&lt;P&gt;That appears to be an exercise to show some of the features of the INTO keyword in PROC SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would NOT recommend using that method in real code unless absolutely forced to by some strange circumstances.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general it is better to keep data in data and not transfer it to strings so you can store it in macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2025 18:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/966638#M376189</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-05-15T18:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: comma separated list using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/966941#M376241</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;thanks a lot for your reply and comments! This is what I think:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) My answer was not an exercise of &lt;EM&gt;select into :list;&lt;/EM&gt; statement. I wrote "I took example in SAS Macro1: essentials course note pdf as my reference code", by that I mean I learnt the &lt;EM&gt;select into :list&lt;/EM&gt; statement and technique from the material, I was not saying all parts of my answer was from the material.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) I came up with my solution like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.1) The original post asks "&lt;STRONG&gt;how to get a comma separated employee list using proc sql&lt;/STRONG&gt;?" This is a typical question that can be solved through &lt;EM&gt;proc sql; select into :list&lt;/EM&gt; statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.2) the original post asks "&lt;STRONG&gt;how to get a comma separated employee list for each department?&lt;/STRONG&gt;" To answer this part of the question, one need to add a &lt;EM&gt;where;&lt;/EM&gt; statement in the &lt;EM&gt;proc sql; select into :list;&lt;/EM&gt; step, and the where statement specifies something like&amp;nbsp;&lt;EM&gt;where deptvar="deptmentname" ;.&amp;nbsp;&lt;/EM&gt;One can repeat the &lt;EM&gt;proc sql; select into :list&lt;/EM&gt;&amp;nbsp; step several times and use different department values in the &lt;EM&gt;where;&lt;/EM&gt; statement. Since the step need to be repeated, creating macro variables that has a list of values for the department is a proper method to use, and this leads to another &lt;EM&gt;proc sql; select into :list&lt;/EM&gt; step, which creates the department value list. One can create the macro variable list through &lt;EM&gt;data _null_;&lt;/EM&gt; and &lt;EM&gt;call symputx();&lt;/EM&gt;, but the &lt;EM&gt;proc sql; select into :list&lt;/EM&gt; came to my mind first so I used that one.&lt;/P&gt;</description>
      <pubDate>Mon, 19 May 2025 13:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/comma-separated-list-using-proc-sql/m-p/966941#M376241</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-05-19T13:26:36Z</dc:date>
    </item>
  </channel>
</rss>

