<?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 get minimum value for the below data? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607312#M17530</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input subject visitnum results;
cards;
101 1 3.9
101 2 2.2
101 3 2.2
101 4 2.0
101 5 0.9
101 6 2.0
;
run;
proc sql;
create table want as
select *,(select min(results) from have 
where subject=a.subject and visitnum &amp;lt; a.visitnum) as min
from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 26 Nov 2019 12:47:51 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-11-26T12:47:51Z</dc:date>
    <item>
      <title>How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607293#M17523</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject visitnum results;
cards;
101 1 1.1
101 2 2.2
101 3 2.2
101 4 2.0
101 5 0.9
101 6 2.0
run;&lt;BR /&gt;
Required Output:
subject visitnum results required
101       1        3.9    .
101       2        2.2    3.9
101       3        2.2    2.2
101       4        2.0    2.2
101       5        0.9    2.0
101       6        2.0    0.9

The logicis for subject we need to get minimum value before to the visitnum&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 12:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607293#M17523</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2019-11-26T12:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607298#M17524</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input subject visitnum results;&lt;BR /&gt;cards;&lt;BR /&gt;101 1 3.9&lt;BR /&gt;101 2 2.2&lt;BR /&gt;101 3 2.2&lt;BR /&gt;101 4 2.0&lt;BR /&gt;101 5 0.9&lt;BR /&gt;101 6 2.0&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Data want;&lt;BR /&gt;set have;&lt;BR /&gt;required=lag(results);&lt;BR /&gt;run;</description>
      <pubDate>Tue, 26 Nov 2019 12:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607298#M17524</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2019-11-26T12:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607299#M17525</link>
      <description>&lt;P&gt;Where does 3.9 come from?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 12:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607299#M17525</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-26T12:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607302#M17527</link>
      <description>&lt;P&gt;Hello sir,&lt;/P&gt;&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;user might have&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;miss spelled instead of (&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1.1)=(101 1 3.9)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class="  language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; subject visitnum results&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1.1&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2.2&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2.2&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;4&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2.0&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;5&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;0.9&lt;/SPAN&gt;
&lt;SPAN class="token number"&gt;101&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;6&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2.0&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 12:24:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607302#M17527</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2019-11-26T12:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607303#M17528</link>
      <description>&lt;P&gt;oh, it's 1.1&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 12:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607303#M17528</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2019-11-26T12:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607304#M17529</link>
      <description>&lt;P&gt;Use a retained variable, by-group processing, and the min() function:&lt;/P&gt;
&lt;P&gt;(based on your example data)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject visitnum results;
cards;
101 1 1.1
101 2 2.2
101 3 2.2
101 4 2.0
101 5 0.9
101 6 2.0
;

data want;
set have;
by subject;
retain required;
if first.subject
then required = min(results,9999); * use sufficiently large value here;
else required = min(results,required);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174522"&gt;@rajeshalwayswel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject visitnum results;
cards;
101 1 1.1
101 2 2.2
101 3 2.2
101 4 2.0
101 5 0.9
101 6 2.0
run;&lt;BR /&gt;
Required Output:
subject visitnum results required
101       1        3.9    .
101       2        2.2    3.9
101       3        2.2    2.2
101       4        2.0    2.2
101       5        0.9    2.0
101       6        2.0    0.9

The logicis for subject we need to get minimum value before to the visitnum&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 12:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607304#M17529</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-26T12:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607312#M17530</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input subject visitnum results;
cards;
101 1 3.9
101 2 2.2
101 3 2.2
101 4 2.0
101 5 0.9
101 6 2.0
;
run;
proc sql;
create table want as
select *,(select min(results) from have 
where subject=a.subject and visitnum &amp;lt; a.visitnum) as min
from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Nov 2019 12:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607312#M17530</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-26T12:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607430#M17535</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/174522"&gt;@rajeshalwayswel&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would use a slightly modified DATA step approach, for example one combining the suggestions from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/90077"&gt;@sivastat08&lt;/a&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by subject;
retain required 0;
required=min(required,lag(results));
if first.subject then required=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or, similarly, without the LAG function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by subject;
retain required;
if first.subject then required=.;
output;
required=min(required,results);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Note: The purpose of the arbitrary initial value 0 for &lt;FONT face="courier new,courier"&gt;required&lt;/FONT&gt; in the first solution is just to avoid the note "&lt;FONT face="courier new,courier"&gt;Missing values were generated&lt;/FONT&gt; ..." for the very first observation.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both variants assume that dataset HAVE is sorted by subject &lt;EM&gt;and&lt;/EM&gt; chronologically within each subject. The advantage of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;'s solution is that it does not require HAVE to be sorted. It assumes that visits of a subject are numbered chronologically, though.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607430#M17535</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-11-26T17:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607436#M17536</link>
      <description>&lt;P&gt;Your data example works with a simple LAG() function call.&lt;/P&gt;
&lt;P&gt;Perhaps you need to update your example where the min is not just the value of the previous observation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  by subject ;
  want = min(want,lag(results));
  if first.subject then want=.;
  retain want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is slighly modified data demonstrates the difference.&lt;/P&gt;
&lt;P&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 subject visitnum results required;
cards;
101       1        3.9    .
101       2        2.2    3.9
101       3        2.0    2.2
101       4        2.2    2.0
101       5        0.9    2.0
101       6        2.0    0.9
;
data want;
  set have ;
  by subject ;
  lag_results=lag(results);
  want = min(want,lag(results));
  if first.subject then call missing(want,lag_results);
  retain want;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Notice the different result for VISTNUM=5?&lt;/P&gt;
&lt;PRE&gt;                                                       lag_
Obs    subject    visitnum    results    required    results    want

 1       101          1         3.9          .          .         .
 2       101          2         2.2         3.9        3.9       3.9
 3       101          3         2.0         2.2        2.2       2.2
 4       101          4         2.2         2.0        2.0       2.0
 5       101          5         0.9         2.0        2.2       2.0
 6       101          6         2.0         0.9        0.9       0.9
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2019 17:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607436#M17536</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-26T17:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607955#M17606</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Hi,

It's work for the some the records but when I haves same visitnum it not working, Could you please have a look on the below data.


data have;
input subject visitnum results;
cards;
101 1 3.9
101 2 1.1
101 3 2.2
101 4 2.0
101 5 0.9
101 5 0.9
;
run;

Required:

101 1 3.9  .
101 2 1.1  3.9
101 3 2.2  1.1
101 4 2.0  1.1
101 5 0.9  1.1
101 5 0.9   0.9&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Nov 2019 04:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607955#M17606</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2019-11-28T04:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607971#M17608</link>
      <description>&lt;P&gt;Using my previous code, with a little twist:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input subject visitnum results;
cards;
101 1 3.9
101 2 1.1
101 3 2.2
101 4 2.0
101 5 0.9
101 5 0.9
;

data want;
set have;
by subject;
retain required;
if first.subject
then required = .;
output;
if first.subject
then required = min(results,9999); * use sufficiently large value here;
else required = min(results,required);
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;subject    visitnum    results    required

  101          1         3.9          .   
  101          2         1.1         3.9  
  101          3         2.2         1.1  
  101          4         2.0         1.1  
  101          5         0.9         1.1  
  101          5         0.9         0.9  
&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Nov 2019 06:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/607971#M17608</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-28T06:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/608030#M17613</link>
      <description>&lt;P&gt;Yes. Try&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; or&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; 's code .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 11:27:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/608030#M17613</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-11-28T11:27:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to get minimum value for the below data?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/608156#M17637</link>
      <description>Thanks so much Kurtbremser. It's worked....</description>
      <pubDate>Fri, 29 Nov 2019 02:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-get-minimum-value-for-the-below-data/m-p/608156#M17637</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2019-11-29T02:46:20Z</dc:date>
    </item>
  </channel>
</rss>

