<?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 creat a new variable in this condition? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208253#M4804</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data Want;&lt;/P&gt;&lt;P&gt;set Have;&lt;/P&gt;&lt;P&gt;count = 0;&lt;/P&gt;&lt;P&gt;array ary(*) var1-var3;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(ary);&lt;/P&gt;&lt;P&gt;if ary(i) = 0 then count+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if count = 3 then var4=1;else var4= 0;&lt;/P&gt;&lt;P&gt;drop count i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Jul 2015 08:06:03 GMT</pubDate>
    <dc:creator>MadhuKorni</dc:creator>
    <dc:date>2015-07-22T08:06:03Z</dc:date>
    <item>
      <title>How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208248#M4799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The data looks like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp;&lt;/P&gt;&lt;P&gt;input var1 var2 var3;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 1 0&lt;/P&gt;&lt;P&gt;0 0 0&lt;/P&gt;&lt;P&gt;0 1 0&lt;/P&gt;&lt;P&gt;1 1 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a few observations with all 0s, how can I efficiently create a new dichotomous variable (e.g., var4) which assigns 1 to those observations and 0 otherwise? The output may look like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 1 0 0&lt;/P&gt;&lt;P&gt;0 0 0 1&lt;/P&gt;&lt;P&gt;0 1 0 0&lt;/P&gt;&lt;P&gt;1 1 1 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should work but it looks unattractive:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want; set temp;&lt;/P&gt;&lt;P&gt;var4 = 0;&lt;/P&gt;&lt;P&gt;if var1 = 0 and var2 = 0 and var3 = 0 then var4 = 1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw, will this work?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want; set temp;&lt;/P&gt;&lt;P&gt;var4 = 0;&lt;/P&gt;&lt;P&gt;array abc var1 var2 var3;&lt;/P&gt;&lt;P&gt;do i = 1 to 3;&lt;/P&gt;&lt;P&gt;if abc(i) = 0 then&amp;nbsp; var4 = 1;&lt;/P&gt;&lt;P&gt;end; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 04:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208248#M4799</guid>
      <dc:creator>NonSleeper</dc:creator>
      <dc:date>2015-07-22T04:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208249#M4800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set temp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if sum(of var1 - var3) eq 0 then var4=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else var4=0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how about this ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 06:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208249#M4800</guid>
      <dc:creator>SASFREAK</dc:creator>
      <dc:date>2015-07-22T06:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208250#M4801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var4 = ^sum(of var1-var3);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The ^ produces a Boolean result since any non-zero value is considered true.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 07:18:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208250#M4801</guid>
      <dc:creator>JerryLeBreton</dc:creator>
      <dc:date>2015-07-22T07:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208251#M4802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is a working solution for this one. But what will it be on a more general issue? I mean, for example, let's say that for variables var1 to var3, value "1" is now "NYC" and "0" is now "Buffalo"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 07:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208251#M4802</guid>
      <dc:creator>NonSleeper</dc:creator>
      <dc:date>2015-07-22T07:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208252#M4803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var4 = ^(var1=var2=var3);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry - missed the point.&amp;nbsp; You want something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var4 = (var1=var2=var3 ='Buffalo&lt;STRONG&gt;'&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your array processing would be fine too of course, and more generic.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 07:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208252#M4803</guid>
      <dc:creator>JerryLeBreton</dc:creator>
      <dc:date>2015-07-22T07:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208253#M4804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data Want;&lt;/P&gt;&lt;P&gt;set Have;&lt;/P&gt;&lt;P&gt;count = 0;&lt;/P&gt;&lt;P&gt;array ary(*) var1-var3;&lt;/P&gt;&lt;P&gt;do i = 1 to dim(ary);&lt;/P&gt;&lt;P&gt;if ary(i) = 0 then count+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;if count = 3 then var4=1;else var4= 0;&lt;/P&gt;&lt;P&gt;drop count i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 08:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208253#M4804</guid>
      <dc:creator>MadhuKorni</dc:creator>
      <dc:date>2015-07-22T08:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208254#M4805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then you would need to count the words or replace:&lt;/P&gt;&lt;P&gt;array var{3};&lt;/P&gt;&lt;P&gt;if countw(catx(',',of var{*}),"NYC") &amp;gt; 0 then var4=1;&amp;nbsp; /* i.e. if NYC exists in the string then the result is 1 */&lt;/P&gt;&lt;P&gt;else var4=0;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jul 2015 08:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208254#M4805</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-07-22T08:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to creat a new variable in this condition?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208255#M4806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was a bit suspicious over my array, because it seems to me the array will assigns 1 if any, but not ALL, of these variables (var1 var2 var3) is 0.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Jul 2015 04:21:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-creat-a-new-variable-in-this-condition/m-p/208255#M4806</guid>
      <dc:creator>NonSleeper</dc:creator>
      <dc:date>2015-07-24T04:21:57Z</dc:date>
    </item>
  </channel>
</rss>

