<?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: creating new variable from possible combinations of other variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688779#M209326</link>
    <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This worked. Thanks a bunch&lt;/P&gt;</description>
    <pubDate>Sun, 04 Oct 2020 18:09:31 GMT</pubDate>
    <dc:creator>benewaa</dc:creator>
    <dc:date>2020-10-04T18:09:31Z</dc:date>
    <item>
      <title>creating new variable from possible combinations of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688772#M209321</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to create a variable which reflects some perception on drug trafficking based on 6 other variables. The variables are all binary and for the new variable, if the values for the existing variables are 1, then the value for the new variable is 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used a code with an array as follows but I am not sure if I am the right path...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA modified;&lt;BR /&gt;SET Basics;&lt;BR /&gt;ARRAY VARIABLE drug_sell drug_store drug_traffic comm_norm_music&lt;BR /&gt;drug_comm_norm_hs drug_comm_music;&lt;BR /&gt;DO OVER VARIABLE;&lt;BR /&gt;IF (VARIABLE) = 1 THEN norm_traffic=1; ELSE norm_traffic=0;&lt;BR /&gt;END;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, if I wanted to modify to code so that the new variable retains a value of 1 if 3 or more of the old variables have value of 1, how would I account for this in the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2020 16:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688772#M209321</guid>
      <dc:creator>benewaa</dc:creator>
      <dc:date>2020-10-04T16:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable from possible combinations of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688774#M209322</link>
      <description>&lt;P&gt;If one "true" is enough to get a true in your result, change your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;norm_traffic = 0;
do over variable;
  if variable = 1 then norm_traffic=1;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can get this easier:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;norm_traffic = (sum(of variable{*}) &amp;gt; 0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2020 16:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688774#M209322</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-04T16:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable from possible combinations of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688776#M209324</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The correction to my code worked ok. the second, however, gives a value of 1 for all participants, which should not be the case.&lt;/P&gt;&lt;P&gt;On how to code so that when 3 or more of my existing variables have a 1, then my new variable assumes a value of 1, is there a way to modify the code for this?&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2020 17:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688776#M209324</guid>
      <dc:creator>benewaa</dc:creator>
      <dc:date>2020-10-04T17:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable from possible combinations of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688778#M209325</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/162849"&gt;@benewaa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correction to my code worked ok. the second, however, gives a value of 1 for all participants, which should not be the case.&lt;/P&gt;
&lt;P&gt;On how to code so that when 3 or more of my existing variables have a 1, then my new variable assumes a value of 1, is there a way to modify the code for this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Data.&lt;/P&gt;
&lt;P&gt;Example data.&lt;/P&gt;
&lt;P&gt;And log of the actual code run.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;norm_traffic3 = (sum(of variable{*}) ge 3);&lt;/LI-CODE&gt;
&lt;P&gt;would do the 3 or more.&lt;/P&gt;
&lt;P&gt;SAS will return 1 for true and 0 for false for comparisons.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2020 17:35:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688778#M209325</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-04T17:35:50Z</dc:date>
    </item>
    <item>
      <title>Re: creating new variable from possible combinations of other variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688779#M209326</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This worked. Thanks a bunch&lt;/P&gt;</description>
      <pubDate>Sun, 04 Oct 2020 18:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/creating-new-variable-from-possible-combinations-of-other/m-p/688779#M209326</guid>
      <dc:creator>benewaa</dc:creator>
      <dc:date>2020-10-04T18:09:31Z</dc:date>
    </item>
  </channel>
</rss>

