<?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: Set a rule where never a value different from 0 or missing appears in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958539#M43043</link>
    <description>Just edited. What I don't know how to say is: when there is never a number (^=0) and conversely when there are always missing or 0s then...do something</description>
    <pubDate>Thu, 06 Feb 2025 14:15:18 GMT</pubDate>
    <dc:creator>NewUsrStat</dc:creator>
    <dc:date>2025-02-06T14:15:18Z</dc:date>
    <item>
      <title>Set a rule where never a value different from 0 or missing appears</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958535#M43041</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;
&lt;P&gt;suppose to have the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB;
  input ID :$20. Var1: $20. Value1 Value2;
cards;
0001 Mydate1  .   .
0001 Mydate2 3.4 3.4 
0002 Mydate1  .   .
0002 Mydate2  3   3
0003 Mydate1  .   .
0003 Mydate2  .   .
0003 Mydate3  .   .
0003 Mydate4  .   .
0003 Mydate5  0  3.4
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would say the following:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if for each ID value 1 is always missing (for every Mydate*) or 0 (i.e., never a number different from 0 or not missing) then where Value1 = 0 then Value1 = Value2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DB1;
  input ID :$20. Var1: $20. Value1 Value2;
cards;
0001 Mydate1  .   .
0001 Mydate2 3.4 3.4 
0002 Mydate1  .   .
0002 Mydate2  3   3
0003 Mydate1  .   .
0003 Mydate2  .   .
0003 Mydate3  .   .
0003 Mydate4  .   .
0003 Mydate5  3.4  3.4
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you help me please?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 14:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958535#M43041</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-02-06T14:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Set a rule where never a value different from 0 or missing appears</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958536#M43042</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if for each ID value 1 is always missing (for every Mydate*) or 0 (i.e., never a number different from 0 or not missing) then where Value1 = 0 then Value1 = Value2.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please explain this further, I do not understand. Please show us the desired output.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 14:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958536#M43042</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-06T14:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Set a rule where never a value different from 0 or missing appears</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958539#M43043</link>
      <description>Just edited. What I don't know how to say is: when there is never a number (^=0) and conversely when there are always missing or 0s then...do something</description>
      <pubDate>Thu, 06 Feb 2025 14:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958539#M43043</guid>
      <dc:creator>NewUsrStat</dc:creator>
      <dc:date>2025-02-06T14:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: Set a rule where never a value different from 0 or missing appears</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958540#M43044</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/134532"&gt;@NewUsrStat&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use a double &lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi28/099-28.pdf" target="_blank" rel="noopener"&gt;DOW loop&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=flag);
do until(last.ID);
  set DB;
  by ID;
  if value1 then flag=1;
end;
do until(last.ID);
  set DB;
  by ID;
  if ~flag &amp;amp; value1=0 then value1=value2;
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the first loop a flag variable is set to 1 if VALUE1 is neither zero nor missing for at least one observation in the current ID BY-group. (Note that the IF condition VALUE1 is true exactly&amp;nbsp;if VALUE1 is neither zero nor missing.) The second loop performs the desired change of VALUE1 if the flag was not set to 1 and writes all observations of the ID to dataset WANT.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 14:29:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958540#M43044</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-02-06T14:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Set a rule where never a value different from 0 or missing appears</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958559#M43047</link>
      <description>&lt;P&gt;Your examples do not seem sufficient to test all of the implications of your requested logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it always the case that you want to replace VALUE1 with the current value of VALUE2?&amp;nbsp; What if the current value of VALUE2 is 0 also?&amp;nbsp; Do you want VALUE1 to stay as 0?&amp;nbsp; What if the current values of VALUE2 is missing? Should VALUE1 be set to missing also?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: It would be much easier to talk about your examples if you named the variables something else, perhaps VAR1 and VAR2, so that you don't confuse when you are talking about the current value of the variable or the variable itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also could the values ever by negative?&amp;nbsp; It not then you are asking if the MAX() value is greater than zero or not.&amp;nbsp; Which makes PROC SQL a likely way to generate what you want since it can re-merge aggregate function results, like MAX(), back onto all of the observations for the BY group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In all of your examples I keep wondering why it is that the values are attached to the wrong observations to begin with?&amp;nbsp; Is there something amiss in the way you are building these datasets to begin with?&amp;nbsp; Could fixing that process get the values onto the right observations so they no longer need to be corrected (or "moved")?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 15:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Set-a-rule-where-never-a-value-different-from-0-or-missing/m-p/958559#M43047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-06T15:56:37Z</dc:date>
    </item>
  </channel>
</rss>

