<?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: concatenation of Binary variables names with value 1. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766089#M242740</link>
    <description>&lt;P&gt;What have you tried?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Almost trivial exercise in looping over 3 values in an array. The Vname function would help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Sep 2021 05:56:24 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-09-05T05:56:24Z</dc:date>
    <item>
      <title>concatenation of Binary variables names with value 1.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766088#M242739</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a data set with the following columns: ID ,Z_Reason1 ,Z_Reason2,Z_Reason3.&lt;/P&gt;
&lt;P&gt;Z_Reason1 ,Z_Reason2,Z_Reason3 are binary variables with reasons for failure.&lt;/P&gt;
&lt;P&gt;I want to calculate a new variable called&amp;nbsp; Concatenate_Reasons that will get following values:&lt;/P&gt;
&lt;P&gt;For ID=1&amp;nbsp; &amp;nbsp;"Z_Reason1"&lt;/P&gt;
&lt;P&gt;For ID=2&amp;nbsp; "Z_Reason1,Z_Reason2"&lt;/P&gt;
&lt;P&gt;For ID=3&amp;nbsp; " "&lt;/P&gt;
&lt;P&gt;FOR ID=4&amp;nbsp; "Z_Reason1,Z_Reason2,Z_Reason3"&lt;/P&gt;
&lt;P&gt;and so on&lt;/P&gt;
&lt;P&gt;As you can see the new variable will get value of concatenation of Binary variables names with value 1.&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input ID Z_reason1  Z_reason2  Z_reason3;
CARDS;
1 1 0 0
2 1 1 0
3 0 0 0
4 1 1 1 
5 0 0 1
6 1 0 0
7 1 0 0
8 0 1 0
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 05:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766088#M242739</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-05T05:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: concatenation of Binary variables names with value 1.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766089#M242740</link>
      <description>&lt;P&gt;What have you tried?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Almost trivial exercise in looping over 3 values in an array. The Vname function would help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Sep 2021 05:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766089#M242740</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-05T05:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: concatenation of Binary variables names with value 1.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766090#M242741</link>
      <description>&lt;P&gt;Here what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;describes in case it's not clear to you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
Input ID Z_reason1  Z_reason2  Z_reason3;
CARDS;
1 1 0 0
2 1 1 0
3 0 0 0
4 1 1 1 
5 0 0 1
6 1 0 0
7 1 0 0
8 0 1 0
;

data want;
  set have;
  length Concatenate_Reasons $100;
  array z_reasons {*} z_reason:;
  do i=1 to dim(z_reasons);
    if z_reasons[i]=1 then
      Concatenate_Reasons=catx(', ',Concatenate_Reasons,vname(z_reasons[i]));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;or if it's only 3 variables you need to test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length Concatenate_Reasons $100;
  Concatenate_Reasons=
    catx(', ',
          ifc(Z_reason1=1,vname(Z_reason1),' '),
          ifc(Z_reason2=1,vname(Z_reason2),' '),
          ifc(Z_reason3=1,vname(Z_reason3),' ')
        );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Sep 2021 00:03:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/concatenation-of-Binary-variables-names-with-value-1/m-p/766090#M242741</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-11T00:03:13Z</dc:date>
    </item>
  </channel>
</rss>

