<?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 concatenate list of variables without duplicates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenate-list-of-variables-without-duplicates/m-p/976018#M378245</link>
    <description>&lt;P&gt;I have two variables, which contains list of dataset variables. A = "VAR1 VAR2 VAR4" and B = "VAR3 VAR4". I want to get string with all 4 VAR1-4 (ascending order is not required). Would be better to solve it inside one Datastep. Is it possible? Or I have to lists VARNAME functions for each of varnum based on NVARS attribute applied to "DSNAME(keep=" || A " " || "B" || ")"? Or I have to use 2 arrays and loops? Is there a better/elegant solution?&lt;/P&gt;</description>
    <pubDate>Tue, 30 Sep 2025 16:09:10 GMT</pubDate>
    <dc:creator>TimurShangareev</dc:creator>
    <dc:date>2025-09-30T16:09:10Z</dc:date>
    <item>
      <title>concatenate list of variables without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-list-of-variables-without-duplicates/m-p/976018#M378245</link>
      <description>&lt;P&gt;I have two variables, which contains list of dataset variables. A = "VAR1 VAR2 VAR4" and B = "VAR3 VAR4". I want to get string with all 4 VAR1-4 (ascending order is not required). Would be better to solve it inside one Datastep. Is it possible? Or I have to lists VARNAME functions for each of varnum based on NVARS attribute applied to "DSNAME(keep=" || A " " || "B" || ")"? Or I have to use 2 arrays and loops? Is there a better/elegant solution?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2025 16:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-list-of-variables-without-duplicates/m-p/976018#M378245</guid>
      <dc:creator>TimurShangareev</dc:creator>
      <dc:date>2025-09-30T16:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: concatenate list of variables without duplicates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenate-list-of-variables-without-duplicates/m-p/976029#M378247</link>
      <description>&lt;P&gt;An array would only be useful if you have multiple variables you wanted to reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that is not what I took your statements to mean.&amp;nbsp; Instead if sounds like you have just TWO variables, both of which have space delimited lists of words.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile cards dsd truncover ;
   input (a b) (:$50.);
cards;
VAR1 VAR2 VAR4,VAR3 VAR4
x y z,a X c
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So make a new variable (or just update one of the existing ones).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length all $100 ;
  all=a;
  do i=1 to countw(b,' ');
    if 0=findw(all,scan(b,i,' '),' ','i') then all=catx(' ',all,scan(b,i,' '));
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1759251974576.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110252i25A90485CA08859C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1759251974576.png" alt="Tom_0-1759251974576.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But it would be simpler if your data structure just had one word per observation.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input type :$10. name :$32. ;
cards;
a VAR1
a VAR2
a VAR4
b VAR3
b VAR4
;
proc sql;
create table want as 
  select distinct name from have
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1759252797817.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/110253iE9149374EB03511B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1759252797817.png" alt="Tom_0-1759252797817.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Sep 2025 17:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenate-list-of-variables-without-duplicates/m-p/976029#M378247</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-09-30T17:20:05Z</dc:date>
    </item>
  </channel>
</rss>

