<?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: Create Dataset/Table with First Observation and One More Observation with Minimum of Column Vari in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520052#M140967</link>
    <description>&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked with only slight modifications : grouped by statement added&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table only_mins as
	select cntno, batchno, min(euclid_dst) as close_batch, l_time, b_time
	from reasonable_dates
	group by cntno
	having euclid_dst = min(Euclid_dst);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks again, cheers!&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
    <pubDate>Mon, 10 Dec 2018 17:07:26 GMT</pubDate>
    <dc:creator>jawhitmire</dc:creator>
    <dc:date>2018-12-10T17:07:26Z</dc:date>
    <item>
      <title>Create Dataset/Table with First Observation and One More Observation with Minimum of Column Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520022#M140959</link>
      <description>&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;I am trying to extract the first observation (cntno=734) and the single observation with minimum Euclidean distance from the following SAS dataset named "reasonable_dates":&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="blue.JPG" style="width: 517px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25512i65DE7084ADC89428/image-size/large?v=v2&amp;amp;px=999" role="button" title="blue.JPG" alt="blue.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The final dataset should be just 2 observations: the row with cntno=734 and the row with the minimum of Euclid_dst.&amp;nbsp; In this case that would be 1056.88 (numeric).&amp;nbsp; I wish to keep all variables in the new dataset: cntno, batchno, and dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Current version is&lt;/P&gt;&lt;P&gt;Current version is&amp;nbsp;9.04.01M5P091317 and I do not have the SAS/STATS package.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First attempt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table only_mins as
	select cntno, batchno, min(euclid_dst) as close_batch
	from reasonable_dates
	group by batchno;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fails because output contains all values.&amp;nbsp; I'm thinking the min() function does not work because I do not have the SAS/STATS package.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second attempt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set reasonable_dates;
	firstsmall=.; secondsmall=.;
	array k[*] euclid_dst:;
	firstsmall=smallest(1,of k[*]);
	secondsmall=smallest(2,of k[*]);
	put firstsmall =;
	put secondsmall = ;
	stop;
	run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Fails to compile with log :&lt;/P&gt;&lt;P&gt;NOTE: Argument 1 to function SMALLEST(2,0) at line 739 column 17 is invalid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Third attempt:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=reasonable_dates min;
	class cntno;
	var euclid_dst;
	output out=new(where=(_type_=1)) min=/autoname;
	run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The output is "new"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="means.JPG" style="width: 236px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25520iC16DDF45C1513A63/image-size/large?v=v2&amp;amp;px=999" role="button" title="means.JPG" alt="means.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is a problem because, well, it isn't a new dataset, Cntno is renamed as Batchno, and the other variable values are missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for looking at my post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520022#M140959</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2018-12-10T16:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dataset/Table with First Observation and One More Observation with Minimum of Column Vari</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520029#M140960</link>
      <description>&lt;P&gt;Post sample data as text please, not as an image. No one really wants to type out your data. &lt;BR /&gt;&lt;BR /&gt;MIN() function is not related to the SAS/STATS package, it isn't working because in SAS, when you select columns that are unique (batchno) it will return all unique values, because you haven't specified how to group it. &lt;BR /&gt;And in a data step, the MIN would mean the min of that row, not of the full column.&lt;BR /&gt;&lt;BR /&gt;Can you also show what you want your output to look like? &lt;BR /&gt;&lt;BR /&gt;If you just want the first two rows, have you considered obs=2 option?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by euclid_dist;
run;

data want;
set have (obs=2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248885"&gt;@jawhitmire&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good day,&lt;/P&gt;
&lt;P&gt;I am trying to extract the first observation (cntno=734) and the single observation with minimum Euclidean distance from the following SAS dataset named "reasonable_dates":&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="blue.JPG" style="width: 517px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25512i65DE7084ADC89428/image-size/large?v=v2&amp;amp;px=999" role="button" title="blue.JPG" alt="blue.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The final dataset should be just 2 observations: the row with cntno=734 and the row with the minimum of Euclid_dst.&amp;nbsp; In this case that would be 1056.88 (numeric).&amp;nbsp; I wish to keep all variables in the new dataset: cntno, batchno, and dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current version is&lt;/P&gt;
&lt;P&gt;Current version is&amp;nbsp;9.04.01M5P091317 and I do not have the SAS/STATS package.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First attempt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table only_mins as
	select cntno, batchno, min(euclid_dst) as close_batch
	from reasonable_dates
	group by batchno;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fails because output contains all values.&amp;nbsp; I'm thinking the min() function does not work because I do not have the SAS/STATS package.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second attempt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set reasonable_dates;
	firstsmall=.; secondsmall=.;
	array k[*] euclid_dst:;
	firstsmall=smallest(1,of k[*]);
	secondsmall=smallest(2,of k[*]);
	put firstsmall =;
	put secondsmall = ;
	stop;
	run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fails to compile with log :&lt;/P&gt;
&lt;P&gt;NOTE: Argument 1 to function SMALLEST(2,0) at line 739 column 17 is invalid&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third attempt:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=reasonable_dates min;
	class cntno;
	var euclid_dst;
	output out=new(where=(_type_=1)) min=/autoname;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output is "new"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="means.JPG" style="width: 236px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25520iC16DDF45C1513A63/image-size/large?v=v2&amp;amp;px=999" role="button" title="means.JPG" alt="means.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This is a problem because, well, it isn't a new dataset, Cntno is renamed as Batchno, and the other variable values are missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for looking at my post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jane&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520029#M140960</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-10T16:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dataset/Table with First Observation and One More Observation with Minimum of Column Vari</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520035#M140962</link>
      <description>Thank you for the quick reply:&lt;BR /&gt;The data set "reasonable_dates" has 10 observations and 7 variables&lt;BR /&gt;Cntno l_day l_time batchno b_day b_time Euclid_dst&lt;BR /&gt;734 053600 12jan2025 0 . . 0.00&lt;BR /&gt;0 . . 375 154200 05jan2025 1061.33&lt;BR /&gt;0 . . 376 113000 06jan2025 1064.12&lt;BR /&gt;0 . . 377 035400 07jan2025 1059.09&lt;BR /&gt;0 . . 382 054800 10jan2025 1056.88&lt;BR /&gt;I would like the output to have 2 rows: the row with cntno=734 (first observation) and the row with the minimum numeric value in the column Euclid_dst.&lt;BR /&gt;So the final dataset will look like this:&lt;BR /&gt;Cntno l_day l_time batchno b_day b_time Euclid_dst&lt;BR /&gt;734 053600 12jan2025 0 . . 0.00&lt;BR /&gt;0 . . 382 054800 10jan2025 1056.88&lt;BR /&gt;&lt;BR /&gt;Jane&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520035#M140962</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2018-12-10T16:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dataset/Table with First Observation and One More Observation with Minimum of Column Vari</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520041#M140964</link>
      <description>Did you try the solution I suggested? It should work fine for what you want?</description>
      <pubDate>Mon, 10 Dec 2018 16:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520041#M140964</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-10T16:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dataset/Table with First Observation and One More Observation with Minimum of Column Vari</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520045#M140966</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248885"&gt;@jawhitmire&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First attempt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table only_mins as
	select cntno, batchno, min(euclid_dst) as close_batch
	from reasonable_dates
	group by batchno;
	quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fails because output contains all values.&amp;nbsp; I'm thinking the min() function does not work because I do not have the SAS/STATS package.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your example data shows only one record per&amp;nbsp;level of BATCHNO. If the remainder of your data is that way then with only one record per batchno the group by forces one record per.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the record with min value (ASSUMES there is only one, which is often a dangerous assumption) then perhaps&lt;/P&gt;
&lt;PRE&gt;proc sql;
	create table only_mins as
	select cntno, batchno, min(euclid_dst) as close_batch
	from reasonable_dates
	having euclid_dist = min(Euclid_dist)
quit;&lt;/PRE&gt;
&lt;P&gt;and then you would have for the final two observation set&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  set reasonable_dates (obs=1)
      only_mins;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Dec 2018 16:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520045#M140966</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-12-10T16:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create Dataset/Table with First Observation and One More Observation with Minimum of Column Vari</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520052#M140967</link>
      <description>&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked with only slight modifications : grouped by statement added&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table only_mins as
	select cntno, batchno, min(euclid_dst) as close_batch, l_time, b_time
	from reasonable_dates
	group by cntno
	having euclid_dst = min(Euclid_dst);
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks again, cheers!&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;</description>
      <pubDate>Mon, 10 Dec 2018 17:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-Dataset-Table-with-First-Observation-and-One-More/m-p/520052#M140967</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2018-12-10T17:07:26Z</dc:date>
    </item>
  </channel>
</rss>

