<?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: prog sql summary function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581984#M165464</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277798"&gt;@Jonison&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Proc SQL, when presented with using the AVG function, first checks the data type of the column AVG is used with. If the type isn't numeric, it doesn't compile. The message you've received tells you this is the case. SQL doesn't care whether or not the actual characters in the column represent what can be interpreted as a number and, unlike the DATA step, doesn't attempt an implicit conversion. You have to do the conversion yourself using the INPUT function, as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want SAS to convert implicitly (and print the note to this effect in the log), you have to do it in the DATA step. However, in my opinion, letting any implicit conversions to occur is bad programming practice. SQL is just more rigid about this and just fails to run if the data type is wrong, which, given how I feel about implicit conversions, is a good thing. I'd much prefer the DATA step, too, to fail at the compilation stage if the data type of a variable fed to a numeric or character function isn't numeric or character, correspondingly. It would deter many SAS users from writing sloppy code and littering the logs with gazillions of data type conversion notes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 18 Aug 2019 03:25:20 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-08-18T03:25:20Z</dc:date>
    <item>
      <title>prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581748#M165378</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	SELECT quote(BAT_NUM) into: ListFP separated by ',' FROM EMWS6.EMCODE2_TRAIN;
   /*CREATE TABLE EMWS6.EMCODE_TRAIN AS*/
	CREATE TABLE TLIST AS 
   SELECT t1.'ResultBelow0.440µm'n,
			 avg(t1.'ResultBelow0.440µm'n,) as AvgResultBelow0_400,
			 t1.BatchNumber
      FROM GDM_DIST.VW_M2000_VALID_DATA t1
      WHERE t1.BatchNumber IN (&amp;amp;ListFP)
		group by t1.BatchNumber; 
	SELECT * FROM TLIST;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Results showed:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Function AVG could not be located.&lt;BR /&gt;WARNING: A GROUP BY clause has been transformed into an ORDER BY clause because neither the SELECT clause nor the optional HAVING clause of the associated table-expression referenced a summary function.&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions are very appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 15:37:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581748#M165378</guid>
      <dc:creator>Jonison</dc:creator>
      <dc:date>2019-08-16T15:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581750#M165379</link>
      <description>&lt;P&gt;Is it perhaps a syntax issue i,e&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  SELECT t1.'ResultBelow0.440µm'n,
			 avg(t1.'ResultBelow0.440µm'n,) as AvgResultBelow0_400,
			 t1.BatchNumber&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should not have a comma after 'n in avg(t1.'ResultBelow0.440µm'n&lt;STRONG&gt;,)&lt;/STRONG&gt; /*try removing this comma*/&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I am not sure of your logic to have the same varnames&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt; &lt;SPAN class="token statement"&gt;SELECT&lt;/SPAN&gt; t1&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'ResultBelow0.440µm'&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;
			 avg&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;t1&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'ResultBelow0.440µm'&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;n&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Aug 2019 15:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581750#M165379</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-16T15:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581780#M165394</link>
      <description>&lt;P&gt;Many thanks for your kind reply.&lt;BR /&gt;The comma has been removed, and the message shows:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to average the column to get average value of that column as a new variable, and only numeric data is in columns.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 17:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581780#M165394</guid>
      <dc:creator>Jonison</dc:creator>
      <dc:date>2019-08-16T17:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581786#M165396</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277798"&gt;@Jonison&lt;/a&gt;&amp;nbsp; &amp;nbsp;Could you please post a sample of your input data and your expected output?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 17:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581786#M165396</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-16T17:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581788#M165397</link>
      <description>It may look like a number but if the variable type is not numeric it cannot be used as a number. Verify your data types and go back and clean up your data input step.</description>
      <pubDate>Fri, 16 Aug 2019 17:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581788#M165397</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-16T17:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581800#M165403</link>
      <description>&lt;P&gt;thanks for your kind reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&g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P&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.335&lt;/TD&gt;&lt;TD&gt;L35P&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.303&lt;/TD&gt;&lt;TD&gt;L35P&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the data extracted from our database, the data was grouped by batch number. I would like to use average value to summarize the data. So each batch will only have one average value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your help in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 17:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581800#M165403</guid>
      <dc:creator>Jonison</dc:creator>
      <dc:date>2019-08-16T17:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581804#M165407</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277798"&gt;@Jonison&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks for your kind reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Result&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Below0.440µm&lt;/TD&gt;
&lt;TD&gt;BatchNumber&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt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
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the data extracted from our database, the data was grouped by batch number. I would like to use average value to summarize the data. So each batch will only have one average value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks for your help in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When someone in this forum (in this case&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;) asks you to go back and verify that the variable type is (or is not) numeric, we need you to look at PROC CONTENTS or the DICTIONARY table of the specific SAS data set or of the database table, and see if the variable in question is shown as having a type of numeric or character. Simply displaying the data as you have done isn't really the answer we are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, since you are getting an error, it seems clear that the values in the first column (such as 0.062) are characters, and so you can't take an average of characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to convert these to numerics, one way to do this is via the INPUT function. Then you can perform mathematical calculations on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;avg(input(t1.'ResultBelow0.440µm'n,best12.)) as AvgResultBelow0_400,&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Aug 2019 18:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581804#M165407</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-16T18:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581827#M165412</link>
      <description>&lt;P&gt;Doesn't look like a numeric value to me. Why is it left aligned instead of right aligned. Why don't all of the values show the same number of decimal places?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input x y :$10. ;
cards;   
0.062 3G5A
0.077 3G5A
0.062 3G5A
0.073 3G5A
0.062 3G5A
0.074 3G5A
0.172 L29S
0.28 L29S
0.274 L29S
0.178 L29S
0.34 L35P
0.297 L35P
0.335 L35P
0.303 L35P
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 154px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31813i7D4DA48C61B97FE8/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Aug 2019 18:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581827#M165412</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-16T18:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: prog sql summary function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581984#M165464</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277798"&gt;@Jonison&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Proc SQL, when presented with using the AVG function, first checks the data type of the column AVG is used with. If the type isn't numeric, it doesn't compile. The message you've received tells you this is the case. SQL doesn't care whether or not the actual characters in the column represent what can be interpreted as a number and, unlike the DATA step, doesn't attempt an implicit conversion. You have to do the conversion yourself using the INPUT function, as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want SAS to convert implicitly (and print the note to this effect in the log), you have to do it in the DATA step. However, in my opinion, letting any implicit conversions to occur is bad programming practice. SQL is just more rigid about this and just fails to run if the data type is wrong, which, given how I feel about implicit conversions, is a good thing. I'd much prefer the DATA step, too, to fail at the compilation stage if the data type of a variable fed to a numeric or character function isn't numeric or character, correspondingly. It would deter many SAS users from writing sloppy code and littering the logs with gazillions of data type conversion notes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Aug 2019 03:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/prog-sql-summary-function/m-p/581984#M165464</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-18T03:25:20Z</dc:date>
    </item>
  </channel>
</rss>

