<?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: Urgent help need for selecting min and max value using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265582#M52257</link>
    <description>&lt;P&gt;I got the solution thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Apr 2016 03:30:01 GMT</pubDate>
    <dc:creator>Cathy</dc:creator>
    <dc:date>2016-04-22T03:30:01Z</dc:date>
    <item>
      <title>Urgent help need for selecting min and max value using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265573#M52253</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data set for demo. where I want to create the avearge percent of weight and height and getting the table containg only 4 observations where min of weight, max of weight and min of height and max of height. But my coding is giving me column of same min and max every observation...Please kindly help me again. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is just an example of table that I want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Ht&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Wt&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Percent of&lt;BR /&gt;Average Ht&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Percent of&lt;BR /&gt;Average Wt&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;155&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;200&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;87.1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;145&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;150&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;171&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;220&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;141&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;110&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the coding what I have done so far;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;sql&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;create table demonew as&lt;/P&gt;&lt;P&gt;select *,&lt;/P&gt;&lt;P&gt;mean(ht) as mean_ht&amp;nbsp; format=&lt;STRONG&gt;6.2&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;(ht/mean(ht)) as pct_total_ht format=Percent8.4,&lt;/P&gt;&lt;P&gt;mean(wt) as mean_wt&amp;nbsp; format=&lt;STRONG&gt;6.2&lt;/STRONG&gt;,&lt;/P&gt;&lt;P&gt;(ht/mean(wt)) as pct_total_wt format=Percent8.4,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;max(ht) as max_ht,&lt;/P&gt;&lt;P&gt;min(wt) as min_wt&lt;/P&gt;&lt;P&gt;from demo&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from demonew&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's what I get with above code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Ht&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Wt&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Percent of&lt;BR /&gt;Average Ht&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Percent of&lt;BR /&gt;Average Wt&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Max Wt&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Max&lt;/STRONG&gt;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;&lt;P&gt;….&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;220&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;171&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 22 Apr 2016 02:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265573#M52253</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-22T02:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help need for selecting min and max value using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265579#M52255</link>
      <description>&lt;P&gt;If there's a column you don't want, drop it from the select statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you can just drop the last two vars from your select statement unless I'm missing something.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 02:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265579#M52255</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-22T02:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help need for selecting min and max value using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265582#M52257</link>
      <description>&lt;P&gt;I got the solution thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 03:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265582#M52257</guid>
      <dc:creator>Cathy</dc:creator>
      <dc:date>2016-04-22T03:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent help need for selecting min and max value using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265598#M52261</link>
      <description>&lt;P&gt;What is the actual question here? &amp;nbsp;It seems to me there are several things in your code. &amp;nbsp;Lets step through it. &amp;nbsp;Your required output appears to HT and WT, so from that I would guess that you want a distinct list of each WT/HT variant, and sums based on that grouping. &amp;nbsp;If thats not the case then why are these here, what are they min and max perhaps? &amp;nbsp;Its not clear. &amp;nbsp;Secondly you select columns you want in the output tables, so if you don't want something, don't select it. &amp;nbsp;Thirdly you are apply SAS formats to the columns. &amp;nbsp;Whilst this may make it look like the value is X.YY, it doesn't change the underlying value. &amp;nbsp;For any output or QC dataset you are better off specifying the rounding in your spec, then applying round() function to the value - that way you and your QC'er will have the same value, otherwise you might have 45.1234 in your data, but format it as 41.12, and the QC'er actually has 45.12 which are not equal. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last SQL step doesn't appear to do anything?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, here is code to create what you want, note formatted consitently, indented etc. for ease of readability (and corrected some typos like HT in the WT calculation):&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table DEMONEW as
  select  distinct
          HT,
          WT,
          round(HT/mean(HT),6.1) as PCT_TOTAL_HT,    
          round(WT/mean(WT),6.1) as PCT_TOTAL_WT
  from    DEMO
  group by HT,
           WT;
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2016 08:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Urgent-help-need-for-selecting-min-and-max-value-using-proc-sql/m-p/265598#M52261</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-22T08:30:26Z</dc:date>
    </item>
  </channel>
</rss>

