<?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: Find min and max of the same column in sql in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384695#M3198</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=customer_club out=customers;
   by Customer_Type Customer_BirthDate;
run;

data clubextremes;
   set customers;
   by Customer_Type;

   retain oldest oldest_bday youngest youngest_bday;
   if first.Customer_Type=1 then do;
	  oldest=Customer_ID;
      oldest_bday=Customer_BirthDate;
   end;
   if last.Customer_Type=1 then do;
      youngest=Customer_ID;
      youngest_bday=Customer_BirthDate;
      agerange=(youngest_bday-oldest_bday)/365.25;
	  output;
   end;
   keep Customer_Type oldest youngest oldest_bday youngest_bday agerange;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is data stpes, but I do not know how to write it in sql.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Aug 2017 17:37:16 GMT</pubDate>
    <dc:creator>ydu180</dc:creator>
    <dc:date>2017-08-01T17:37:16Z</dc:date>
    <item>
      <title>Find min and max of the same column in sql</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384682#M3196</link>
      <description>&lt;P&gt;I need to print a table usin sql to show youngest and oldest of each customer_type.&lt;/P&gt;&lt;P&gt;The desired table is&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="微信图片_20170802010653.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14270i35AB137C529790F8/image-size/large?v=v2&amp;amp;px=999" role="button" title="微信图片_20170802010653.png" alt="微信图片_20170802010653.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;oldest = the Customer_ID value of the oldest customer&lt;BR /&gt;oldest_bday = the Customer_Birthdate of the oldest customer&lt;BR /&gt;youngest = the Customer_ID value of the youngest customer&lt;BR /&gt;youngest_bday = the Customer_Birthdate of the youngest customer&lt;BR /&gt;agerange = the number of years (rounded to the nearest tenth) between the age of&lt;BR /&gt;the oldest and youngest members of that type; use Customer_Birthdate instead of theCustomer_Age variable to calculate agerange&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried four sql, can anyone tell how to write this and let it be more efficient?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 17:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384682#M3196</guid>
      <dc:creator>ydu180</dc:creator>
      <dc:date>2017-08-01T17:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find min and max of the same column in sql</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384685#M3197</link>
      <description>&lt;P&gt;What does your code look like so far?&lt;/P&gt;
&lt;P&gt;Please post data as text minimum and ideally as a data step. No one really wants to type out both your data and code for an answer.&amp;nbsp;&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/149070"&gt;@ydu180&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I need to print a table usin sql to show youngest and oldest of each customer_type.&lt;/P&gt;
&lt;P&gt;The desired table is&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="微信图片_20170802010653.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14270i35AB137C529790F8/image-size/large?v=v2&amp;amp;px=999" role="button" title="微信图片_20170802010653.png" alt="微信图片_20170802010653.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;oldest = the Customer_ID value of the oldest customer&lt;BR /&gt;oldest_bday = the Customer_Birthdate of the oldest customer&lt;BR /&gt;youngest = the Customer_ID value of the youngest customer&lt;BR /&gt;youngest_bday = the Customer_Birthdate of the youngest customer&lt;BR /&gt;agerange = the number of years (rounded to the nearest tenth) between the age of&lt;BR /&gt;the oldest and youngest members of that type; use Customer_Birthdate instead of theCustomer_Age variable to calculate agerange&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried four sql, can anyone tell how to write this and let it be more efficient?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 17:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384685#M3197</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-01T17:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find min and max of the same column in sql</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384695#M3198</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=customer_club out=customers;
   by Customer_Type Customer_BirthDate;
run;

data clubextremes;
   set customers;
   by Customer_Type;

   retain oldest oldest_bday youngest youngest_bday;
   if first.Customer_Type=1 then do;
	  oldest=Customer_ID;
      oldest_bday=Customer_BirthDate;
   end;
   if last.Customer_Type=1 then do;
      youngest=Customer_ID;
      youngest_bday=Customer_BirthDate;
      agerange=(youngest_bday-oldest_bday)/365.25;
	  output;
   end;
   keep Customer_Type oldest youngest oldest_bday youngest_bday agerange;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is data stpes, but I do not know how to write it in sql.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 17:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384695#M3198</guid>
      <dc:creator>ydu180</dc:creator>
      <dc:date>2017-08-01T17:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find min and max of the same column in sql</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384697#M3200</link>
      <description>&lt;P&gt;Your previous answer said you 'tried four sql'. What does that look like? I get that it's not correct but I'd like to see what you've tried so far.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a basic tutorial that may get you started.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/collapsing-across-observations-using-proc-sql/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/collapsing-across-observations-using-proc-sql/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2017 17:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/384697#M3200</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-01T17:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find min and max of the same column in sql</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/385537#M3223</link>
      <description>&lt;P&gt;You haven't given us a sample of your disaggregate data so I can only give you an example with another data set. Here's how you would find the min and max of the age column by sex in SASHELP.CLASS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class;
by sex;
run;

Proc sql;
	select sex, max(age) as oldest, min(age) as youngest
	from class
	group by sex;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 00:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Find-min-and-max-of-the-same-column-in-sql/m-p/385537#M3223</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-08-04T00:56:19Z</dc:date>
    </item>
  </channel>
</rss>

