<?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: how to check if multiple variables for a single observation/record has the same value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831622#M328647</link>
    <description>yes ! order matters.&lt;BR /&gt;</description>
    <pubDate>Fri, 02 Sep 2022 20:56:30 GMT</pubDate>
    <dc:creator>abhisas1</dc:creator>
    <dc:date>2022-09-02T20:56:30Z</dc:date>
    <item>
      <title>how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831614#M328639</link>
      <description>&lt;P&gt;I have multiple variables and I want to concatenate all the the values in the variables and i do not want same value twice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the below example i want to create new variable called var6 by concatenating all the values from var1 to var5 for each ID. but i do&amp;nbsp; not want a value repeated. for instance, for ID 1 as advil twice. but in var6 i want it to be seen only once . ex: Var6 = mic,advil,keyboard,mouse&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data chk;&lt;BR /&gt;input id var1$ var2$ var3$ var4$ var5$;&lt;/P&gt;&lt;P&gt;datalines;&lt;BR /&gt;1 mic advil keyboard advil mouse&lt;BR /&gt;2 mouse mouse keyboard perfume notebook&lt;BR /&gt;3 book wire plug desktop charger&lt;BR /&gt;4 mobile laptop mouse desktop phone&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 19:41:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831614#M328639</guid>
      <dc:creator>abhisas1</dc:creator>
      <dc:date>2022-09-02T19:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831621#M328646</link>
      <description>&lt;P&gt;Does order matter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set chk;

array _v(*) var:;
length want $200.;

do i=1 to dim(_v);
if whichc(_v(i), of _v(*)) = i then want=catx(", ", want, _v(i));
end;


run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356985"&gt;@abhisas1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have multiple variables and I want to concatenate all the the values in the variables and i do not want same value twice.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the below example i want to create new variable called var6 by concatenating all the values from var1 to var5 for each ID. but i do&amp;nbsp; not want a value repeated. for instance, for ID 1 as advil twice. but in var6 i want it to be seen only once . ex: Var6 = mic,advil,keyboard,mouse&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data chk;&lt;BR /&gt;input id var1$ var2$ var3$ var4$ var5$;&lt;/P&gt;
&lt;P&gt;datalines;&lt;BR /&gt;1 mic advil keyboard advil mouse&lt;BR /&gt;2 mouse mouse keyboard perfume notebook&lt;BR /&gt;3 book wire plug desktop charger&lt;BR /&gt;4 mobile laptop mouse desktop phone&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 21:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831621#M328646</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-02T21:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831622#M328647</link>
      <description>yes ! order matters.&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Sep 2022 20:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831622#M328647</guid>
      <dc:creator>abhisas1</dc:creator>
      <dc:date>2022-09-02T20:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831623#M328648</link>
      <description>&lt;P&gt;Solution above incorporates order.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 21:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831623#M328648</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-02T21:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831624#M328649</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356985"&gt;@abhisas1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;yes ! order matters.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If there is a specific order that you have in mind then you need to provide it.&lt;/P&gt;
&lt;P&gt;If the specific order is not critical in the final as long as it is consistent with the words then this may do what you want or get you started.&lt;/P&gt;
&lt;P&gt;First copy the existing values into new variables (prevents loss of original data if there is a logic problem) in an array; sort the array; then remove adjacent duplicates. You didn't describe a delimiter to separate the values so I chose a comma. The catx function nicely drops any missing values when concatenating this way.&lt;/P&gt;
&lt;P&gt;After fairly sure that the result is as desired drop the loop counter and the array. Could have made X temporary but might want the information for debugging.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data chk;
   input id var1$ var2$ var3$ var4$ var5$;
   array v(*) var:;
   array x(5) $ 8;
   do i=1 to dim(x);
      x[i]=v[i];
   end;
   call sortc(of x(*));
   do i=1 to (dim(x) - 1);
      if x[i]=x[i+1] then call missing(x[i]);
   end;
   var6 = catx(',',of x(*));
   drop i x:;
datalines;
1 mic advil keyboard advil mouse
2 mouse mouse keyboard perfume notebook
3 book wire plug desktop charger
4 mobile laptop mouse desktop phone
;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2022 21:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831624#M328649</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-02T21:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831629#M328653</link>
      <description>worked perfectly. Thank you so much for detailed step by step explanation.</description>
      <pubDate>Fri, 02 Sep 2022 23:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831629#M328653</guid>
      <dc:creator>abhisas1</dc:creator>
      <dc:date>2022-09-02T23:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: how to check if multiple variables for a single observation/record has the same value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831648#M328666</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data chk;
   input id var1$ var2$ var3$ var4$ var5$;
   array v(*) var:;
   array x(5) $ 8;
   n=0;
   do i=1 to dim(x);
      if v[i] not in x then do;n+1;x[n]=v[i];end;
   end;
   var6 = catx(',',of x(*));
   drop i x: n;
datalines;
1 mic advil keyboard advil mouse
2 mouse mouse keyboard perfume notebook
3 book wire plug desktop charger
4 mobile laptop mouse desktop phone
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Sep 2022 09:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-check-if-multiple-variables-for-a-single-observation/m-p/831648#M328666</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-03T09:56:17Z</dc:date>
    </item>
  </channel>
</rss>

