<?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 compare two numeric observations and retain the first instance in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558636#M155917</link>
    <description>&lt;P&gt;I have a dataset similar to this. I want to compare fcst_val and val variables and retain the instance of desc column where the fcst_val less than or equal to the val.&amp;nbsp;&lt;BR /&gt;Here is an example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input type $ desc $ mo fcst_val val; 
datalines; 
A D2 0 100 1000
A D1 1 100 1050
A B1 2 100 1100
B D1 0 200 150
B B0 1 200 250
B D2 2 200 300
B B1 3 200 350
c D2 0 400 10 
C D1 1 400 300
C B1 1 400 400
;
run;

data want; 
input type $ desc $ mo fcst_val val new_val; 
datalines; 
A D2 0 100 1000  D2
A D1 1 100 1050  D2    
A B1 2 100 1100  D2 
B D1 0 200 150   B0
B B0 1 200 250   B0
B D2 2 200 300   B0
B B1 3 200 350   B0
c D2 0 400 10    B1
C D1 1 400 300   B1
C B1 1 400 500   B1
;
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>Tue, 14 May 2019 14:38:15 GMT</pubDate>
    <dc:creator>zqkal</dc:creator>
    <dc:date>2019-05-14T14:38:15Z</dc:date>
    <item>
      <title>compare two numeric observations and retain the first instance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558636#M155917</link>
      <description>&lt;P&gt;I have a dataset similar to this. I want to compare fcst_val and val variables and retain the instance of desc column where the fcst_val less than or equal to the val.&amp;nbsp;&lt;BR /&gt;Here is an example:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input type $ desc $ mo fcst_val val; 
datalines; 
A D2 0 100 1000
A D1 1 100 1050
A B1 2 100 1100
B D1 0 200 150
B B0 1 200 250
B D2 2 200 300
B B1 3 200 350
c D2 0 400 10 
C D1 1 400 300
C B1 1 400 400
;
run;

data want; 
input type $ desc $ mo fcst_val val new_val; 
datalines; 
A D2 0 100 1000  D2
A D1 1 100 1050  D2    
A B1 2 100 1100  D2 
B D1 0 200 150   B0
B B0 1 200 250   B0
B D2 2 200 300   B0
B B1 3 200 350   B0
c D2 0 400 10    B1
C D1 1 400 300   B1
C B1 1 400 500   B1
;
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>Tue, 14 May 2019 14:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558636#M155917</guid>
      <dc:creator>zqkal</dc:creator>
      <dc:date>2019-05-14T14:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: compare two numeric observations and retain the first instance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558646#M155922</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45150"&gt;@zqkal&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have; 
input type $ desc $ mo fcst_val val; 
datalines; 
A D2 0 100 1000
A D1 1 100 1050
A B1 2 100 1100
B D1 0 200 150
B B0 1 200 250
B D2 2 200 300
B B1 3 200 350
C D2 0 400 10 
C D1 1 400 300
C B1 1 400 500
;
run;

data want;
do until(last.type);
set have;
by type;
length new_val $10;
if fcst_val&amp;lt;val and missing(new_val) then new_val=desc;
end;
do until(last.type);
set have;
by type;
output;
end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 May 2019 15:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558646#M155922</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-14T15:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: compare two numeric observations and retain the first instance</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558666#M155928</link>
      <description>Thanks for your help</description>
      <pubDate>Tue, 14 May 2019 15:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compare-two-numeric-observations-and-retain-the-first-instance/m-p/558666#M155928</guid>
      <dc:creator>zqkal</dc:creator>
      <dc:date>2019-05-14T15:51:45Z</dc:date>
    </item>
  </channel>
</rss>

