<?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: Using proc sql to create min and max in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645170#M192829</link>
    <description>&lt;OL&gt;
&lt;LI&gt;Use the "little running man" icon to post code, otherwise we only see that ugly spaghetti code without any formatting&lt;/LI&gt;
&lt;LI&gt;adapt the code like this:&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
minval = 1e200;
maxval = .;
do until (last.paramcd);
  set have;
  by subjid paramcd;
  if lbnam = 'CVC'
  then do;
    maxval = max(maxval,aval);
    minval = min(minval,aval);
  end;
end;
do until (last.paramcd);
  set have;
  by subjid paramcd;
  if lbname = 'CVC'
  then do;
    if aval = maxval
    then do;
      dtype = "max";
      maxval = .;
    end;
    if aval = minval
    then do;
      dtype = "min";
      minval = .;
    end;
  end;
  output;
  dtype = "";
end;
drop minval maxval;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 May 2020 06:00:40 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-05-05T06:00:40Z</dc:date>
    <item>
      <title>Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644417#M192471</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a new variable that indicates a minimum value and a maximum value of a parameter by subjid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically trying to follow this specification:&lt;/P&gt;&lt;P&gt;Per SUBJID &amp;amp; PARAM:&lt;BR /&gt;MAXIMUM = the first record with the largest AVAL&lt;BR /&gt;MINIMUM = the first record with the smallest AVAL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, i'm having trouble with my proc sql syntax&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table lb2 as&lt;BR /&gt;select subjid, param, aval,&lt;BR /&gt;min(AVAL) as DTYPE="Max",&lt;BR /&gt;max(AVAL) as DTYPE="Min",&lt;BR /&gt;from lb&lt;BR /&gt;group by subjid param;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 00:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644417#M192471</guid>
      <dc:creator>Dregerator</dc:creator>
      <dc:date>2020-05-01T00:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644428#M192473</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301047"&gt;@Dregerator&lt;/a&gt;&amp;nbsp; I can only spot some minor syntax error in your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table lb2 as
select subjid, param, 
min(AVAL) as DTYPE_min label="Max",
max(AVAL) as DTYPE_max label="Min"
from lb
group by subjid, param;
quit;

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 May 2020 01:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644428#M192473</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-01T01:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644433#M192475</link>
      <description>&lt;P&gt;What happens if you have a tie for the min or max?&lt;/P&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/301047"&gt;@Dregerator&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to create a new variable that indicates a minimum value and a maximum value of a parameter by subjid.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically trying to follow this specification:&lt;/P&gt;
&lt;P&gt;Per SUBJID &amp;amp; PARAM:&lt;BR /&gt;MAXIMUM = the first record with the largest AVAL&lt;BR /&gt;MINIMUM = the first record with the smallest AVAL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, i'm having trouble with my proc sql syntax&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table lb2 as&lt;BR /&gt;select subjid, param, aval,&lt;BR /&gt;min(AVAL) as DTYPE="Max",&lt;BR /&gt;max(AVAL) as DTYPE="Min",&lt;BR /&gt;from lb&lt;BR /&gt;group by subjid param;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 01:59:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644433#M192475</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-01T01:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644436#M192477</link>
      <description>Hi,&lt;BR /&gt;So I actually want this&lt;BR /&gt;&lt;BR /&gt;For example lets say i have this set of data:&lt;BR /&gt;&lt;BR /&gt;subjid paramcd aval&lt;BR /&gt;1 ALT 34&lt;BR /&gt;1 ALT 39&lt;BR /&gt;1 ALT 28&lt;BR /&gt;1 ALT 28&lt;BR /&gt;1 ALT 40&lt;BR /&gt;1 ALT 40&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 9&lt;BR /&gt;1 APT 9&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 12&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I want the variable DTYPE to indicate the first max value and the first min value:&lt;BR /&gt;subjid paramcd aval dtype&lt;BR /&gt;1 ALT 34&lt;BR /&gt;1 ALT 39&lt;BR /&gt;1 ALT 28 min&lt;BR /&gt;1 ALT 28&lt;BR /&gt;1 ALT 40 max&lt;BR /&gt;1 ALT 40&lt;BR /&gt;1 APT 15 max&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 9 min&lt;BR /&gt;1 APT 9&lt;BR /&gt;1 APT 15&lt;BR /&gt;1 APT 12&lt;BR /&gt;</description>
      <pubDate>Fri, 01 May 2020 02:11:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644436#M192477</guid>
      <dc:creator>Dregerator</dc:creator>
      <dc:date>2020-05-01T02:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644446#M192481</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301047"&gt;@Dregerator&lt;/a&gt;&amp;nbsp; Proc SQL is ill suited for this kind of problem other than the fact one may deem this as a fun puzzle to solve at 11pm eastern. Elders like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp; are likely to offer better and appropriate advice,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input subjid paramcd $ aval;
cards;
1 ALT 34
1 ALT 39
1 ALT 28
1 ALT 28
1 ALT 40
1 ALT 40
1 APT 15
1 APT 15
1 APT 15
1 APT 9
1 APT 9
1 APT 15
1 APT 12
;

proc sql;
create table want(drop=rn min max) as
select * , case when min(ifn(min=aval,rn,.))=rn then 'min'
when min(ifn(max=aval,rn,.))=rn	then 'max' else ' ' end as dtype
from
(select *, monotonic() as rn ,min(aval) as min, max(aval) as max
from have
group by subjid,paramcd) 
group by subjid, paramcd
order by rn;
quit;

proc print noobs;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="results.PNG" style="width: 340px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38962i0171B373C9E3964D/image-size/large?v=v2&amp;amp;px=999" role="button" title="results.PNG" alt="results.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 03:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644446#M192481</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-01T03:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644461#M192490</link>
      <description>&lt;P&gt;The proper tool is, as most often in SAS data preparation, the DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
minval = 1e200;
maxval = .;
do until (last.paramcd);
  set have;
  by subjid paramcd;
  maxval = max(maxval,aval);
  minval = min(minval,aval);
end;
do until (last.paramcd);
  set have;
  by subjid paramcd;
  if aval = maxval
  then do;
    dtype = "max";
    maxval = .;
  end;
  if aval = minval
  then do;
    dtype = "min";
    minval = .;
  end;
  output;
  dtype = "";
end;
drop minval maxval;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Although it has two set statements, physically it will do a single sequential pass through the dataset, with no remerges needed.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 07:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644461#M192490</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-01T07:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644716#M192620</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301047"&gt;@Dregerator&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also do this, and then sort your data according to CDISC guidelines (e.g. for BDS:&lt;/P&gt;
&lt;DIV class="page" title="Page 14"&gt;
&lt;DIV class="section"&gt;
&lt;DIV class="layoutArea"&gt;
&lt;DIV class="column"&gt;
&lt;P&gt;&lt;SPAN&gt;USUBJID, PARAMCD, AVISIT)&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
	by subjid paramcd aval;
run;

data have;
	set have;
	by subjid paramcd;
	if first.paramcd then dtype="Min";
	if last.paramcd then dtype="Max";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 May 2020 14:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/644716#M192620</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-02T14:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645113#M192780</link>
      <description>&lt;P&gt;Hi thank you this is useful, however, I'm trying to add on a specific condition without subsetting. I'm trying to add the condition LBNAM="CVC" basically out of the whole dataset I only what this min and max to occur where LBNAM="CVC" without reducing the number of observations in the whole dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried doing the following but it doesn't work, as it keeps applying values to other LBNAMs&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;minval = 1e200;&lt;BR /&gt;maxval = .;&lt;BR /&gt;do until (last.paramcd);&lt;BR /&gt;set have;&lt;BR /&gt;if LBNAM = "CVC" then do;&lt;BR /&gt;by usubjid paramcd;&lt;BR /&gt;maxval = max(maxval,aval);&lt;BR /&gt;minval = min(minval,aval);&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;do until (last.paramcd);&lt;BR /&gt;set have;&lt;BR /&gt;by usubjid paramcd;&lt;BR /&gt;if aval = maxval&lt;BR /&gt;dtype = "max";&lt;BR /&gt;maxval = .;&lt;BR /&gt;end;&lt;BR /&gt;if aval = minval&lt;BR /&gt;then do;&lt;BR /&gt;dtype = "min";&lt;BR /&gt;minval = .;&lt;BR /&gt;end;&lt;BR /&gt;output;&lt;BR /&gt;dtype = "";&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;drop minval maxval;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2020 21:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645113#M192780</guid>
      <dc:creator>Dregerator</dc:creator>
      <dc:date>2020-05-04T21:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645114#M192781</link>
      <description>&lt;P&gt;Hi, is there a way to add a condition in this proc sql syntax to only do this when LBNAM="CVC" by any chance, without subsetting the whole dataset. Basically, I want it to perform this calculation only where LBNAM="CVC" out of all the 10 LBNAM's.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2020 21:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645114#M192781</guid>
      <dc:creator>Dregerator</dc:creator>
      <dc:date>2020-05-04T21:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645127#M192792</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301047"&gt;@Dregerator&lt;/a&gt;&amp;nbsp;Sure I can try, albeit I don't see any variable by the name&amp;nbsp;&lt;SPAN&gt;LBNAM and itsvalues in the sample provided by you. Can you please post a modified sample and the corresponding expected output sample so that I have something to refer to. Thanks!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2020 22:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645127#M192792</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-04T22:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645170#M192829</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Use the "little running man" icon to post code, otherwise we only see that ugly spaghetti code without any formatting&lt;/LI&gt;
&lt;LI&gt;adapt the code like this:&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
minval = 1e200;
maxval = .;
do until (last.paramcd);
  set have;
  by subjid paramcd;
  if lbnam = 'CVC'
  then do;
    maxval = max(maxval,aval);
    minval = min(minval,aval);
  end;
end;
do until (last.paramcd);
  set have;
  by subjid paramcd;
  if lbname = 'CVC'
  then do;
    if aval = maxval
    then do;
      dtype = "max";
      maxval = .;
    end;
    if aval = minval
    then do;
      dtype = "min";
      minval = .;
    end;
  end;
  output;
  dtype = "";
end;
drop minval maxval;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 May 2020 06:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645170#M192829</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-05T06:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645368#M192911</link>
      <description>&lt;P&gt;Hi I figured it , I subsetted the data into two groups. One with LBNAM="CVC" and one group without it.&amp;nbsp; Then performed the calculation via your code below, then set those subjects back with the group without the LBNAM="CVC" . However, I was hoping if your proc sql could be revised to also put Maximum as well if the aval is the same for example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;subjid paramcd aval&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 34&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 39&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 28&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 28&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 40&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 40&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 12&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 ABC 9&lt;/P&gt;&lt;P&gt;1 ABC 9&lt;/P&gt;&lt;P&gt;1 ABC 9&lt;/P&gt;&lt;P&gt;1 ABC 9&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want the variable DTYPE to indicate the first max value and the first min value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;subjid paramcd aval dtype&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 34&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 39&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 28 min&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 28&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 40 max&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 ALT 40&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15 max&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 9 min&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 9&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 APT 12&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;1 ABC 9 min&lt;/P&gt;&lt;P&gt;1 ABC 9 max&lt;/P&gt;&lt;P&gt;1 ABC 9&lt;/P&gt;&lt;P&gt;1 ABC 9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When aval values are same, then MIN and MAX should have same value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 18:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645368#M192911</guid>
      <dc:creator>Dregerator</dc:creator>
      <dc:date>2020-05-05T18:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645421#M192928</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/301047"&gt;@Dregerator&lt;/a&gt;&amp;nbsp;Please find the below modified code that should meet your additional requirement. While I enjoy crazy solutions sometimes that would generally be deemed not recommended, by all means give it a thought to go for a rather straight forward Datastep solution offered by others. Lately, I am getting increasingly bored with the predictable datastep solutions and so me being crazy likes to experiment crazy solutions for fun. Though against ethics as it may sound, admittedly I like some entertainment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And please do relax, the contributors here in this community practice SAS religiously and do stick to the same thread and by all means knock the doors for help in the same thread. Trust me, You will get your solution. Take care and have fun!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input subjid paramcd $ aval;
cards;
1 ALT 34
1 ALT 39
1 ALT 28
1 ALT 28
1 ALT 40
1 ALT 40
1 APT 15
1 APT 15
1 APT 15
1 APT 9
1 APT 9
1 APT 15
1 APT 12
1 ABC 9
1 ABC 9
1 ABC 9
1 ABC 9
;


proc sql;
create table want(drop=rn min max) as
select * , case when min(ifn(min=aval and min ne max,rn,.))=rn then 'min'
when min(ifn(max=aval and min ne max,rn,.))=rn	then 'max' 
when min(ifn(min=aval and  min=max,rn,.))=rn then 'min'
when min(ifn(min=aval and  min=max,rn,.))+1=rn then 'max'
else ' ' end as dtype
from
(select *, monotonic() as rn ,min(aval) as min, max(aval) as max
from have
group by subjid,paramcd) 
group by subjid, paramcd
order by rn;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;subjid paramcd aval dtype 
1 ALT 34   
1 ALT 39   
1 ALT 28 min 
1 ALT 28   
1 ALT 40 max 
1 ALT 40   
1 APT 15 max 
1 APT 15   
1 APT 15   
1 APT 9 min 
1 APT 9   
1 APT 15   
1 APT 12   
1 ABC 9 min 
1 ABC 9 max 
1 ABC 9   
1 ABC 9   

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 21:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645421#M192928</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-05T21:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using proc sql to create min and max</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645433#M192938</link>
      <description>&lt;P&gt;Why not use&amp;nbsp;Proc summary?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc summary nway data=lb; 
class subjid param;
var aval;
output out=lb2
 min=Min
 max=Max
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 05 May 2020 22:11:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-proc-sql-to-create-min-and-max/m-p/645433#M192938</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2020-05-05T22:11:48Z</dc:date>
    </item>
  </channel>
</rss>

