<?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: Calculating Averages of missing values in SQL in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640955#M21795</link>
    <description>&lt;P&gt;Here is the full LOG:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;721 Proc sql inobs=100;&lt;BR /&gt;722 create table DAILYCLEAN as&lt;BR /&gt;723 select USAF, WBAN, (LAT)/1000 as LAT, (LONG)/1000 as LONG, year, month, day,&lt;BR /&gt;724 N(COVER)-NMISS(COVER) as COVERCOUNT,&lt;BR /&gt;725 AVG(COVER) as AVGCOVER,&lt;BR /&gt;726 N(ELEV)-NMISS(ELEV) as ELEVCOUNT,&lt;BR /&gt;727 AVG(CASE ELEV WHEN 9999 THEN NULL ELSE ELEV END) as ELEV,&lt;BR /&gt;728 N(TEMP)-NMISS(TEMP) as TEMPCOUNT,&lt;BR /&gt;729 AVG(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as AVGTEMP,&lt;BR /&gt;730 RANGE(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as RANGETEMP,&lt;BR /&gt;731 MAX(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as HITEMP,&lt;BR /&gt;732 MIN(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as LOTEMP,&lt;BR /&gt;733 N(PRESSURE)-NMISS(PRESSURE) as PRESSURECOUNT,&lt;BR /&gt;734 AVG(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as AVGPRESSURE,&lt;BR /&gt;735 MAX(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as HIPRESSURE,&lt;BR /&gt;736 MIN(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as LOPRESSURE&lt;BR /&gt;737 from "D:\WeatherandZipFiles\COVERNUMERIC.sas7bdat"&lt;BR /&gt;738 group by USAF, WBAN, LAT, LONG, year, month, day;&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The RANGE summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: NULL.&lt;BR /&gt;739 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;740 run;&lt;/P&gt;</description>
    <pubDate>Sat, 18 Apr 2020 14:51:28 GMT</pubDate>
    <dc:creator>CJRPHD</dc:creator>
    <dc:date>2020-04-18T14:51:28Z</dc:date>
    <item>
      <title>Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640946#M21792</link>
      <description>&lt;P&gt;I am working with a NOAA weather dataset that codes missing information as some combination of "9". Below is my code to format the data into useful information. In some cases I need to scale variables by a factor of 10 and/or replace "9" values with missing values so that average/max/min calculations are accurate.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I am facing is that in some instances, all observations within the group I defined are missing and both the average function and scaling produces an error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset is gigantic, so to test the code I've only been using the first 100 observations.&lt;/P&gt;&lt;P&gt;Is there a workaround to produce "missing" for an average of missing values and/or be able to properly scale variables when at least one observation isn't missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql inobs=100;&lt;BR /&gt;create table DAILYCLEAN as&lt;BR /&gt;select USAF, WBAN, (LAT)/1000 as LAT, (LONG)/1000 as LONG, year, month, day,&lt;BR /&gt;N(COVER)-NMISS(COVER) as COVERCOUNT,&lt;BR /&gt;AVG(COVER) as AVGCOVER,&lt;BR /&gt;N(ELEV)-NMISS(ELEV) as ELEVCOUNT,&lt;BR /&gt;AVG(CASE ELEV WHEN 9999 THEN NULL ELSE ELEV END) as ELEV,&lt;BR /&gt;N(TEMP)-NMISS(TEMP) as TEMPCOUNT,&lt;BR /&gt;AVG(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as AVGTEMP,&lt;BR /&gt;RANGE(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as RANGETEMP,&lt;BR /&gt;MAX(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as HITEMP,&lt;BR /&gt;MIN(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as LOTEMP,&lt;BR /&gt;N(PRESSURE)-NMISS(PRESSURE) as PRESSURECOUNT,&lt;BR /&gt;AVG(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as AVGPRESSURE,&lt;BR /&gt;MAX(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as HIPRESSURE,&lt;BR /&gt;MIN(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as LOPRESSURE,&lt;BR /&gt;from "D:\WeatherandZipFiles\COVERNUMERIC.sas7bdat"&lt;BR /&gt;group by USAF, WBAN, LAT, LONG, year, month, day;&lt;BR /&gt;quit;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 13:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640946#M21792</guid>
      <dc:creator>CJRPHD</dc:creator>
      <dc:date>2020-04-18T13:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640948#M21793</link>
      <description>&lt;P&gt;Could you share your error?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to emulate your case bud I see no errors in AVG with all null group:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
  do i = 1,2,3;
    do _N_ = 1 to 3;
      if mod(i,2) then x = floor(10*ranuni(1));
                  else x = .;
      output;
    end;
  end;
run;
proc print;
run;


proc sql;
  select 
    i
  , avg(x) as a1
  , avg(case when x = 9 then . else x end) as a2
  from 
    x
  group by 
    i
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 14:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640948#M21793</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T14:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640955#M21795</link>
      <description>&lt;P&gt;Here is the full LOG:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;721 Proc sql inobs=100;&lt;BR /&gt;722 create table DAILYCLEAN as&lt;BR /&gt;723 select USAF, WBAN, (LAT)/1000 as LAT, (LONG)/1000 as LONG, year, month, day,&lt;BR /&gt;724 N(COVER)-NMISS(COVER) as COVERCOUNT,&lt;BR /&gt;725 AVG(COVER) as AVGCOVER,&lt;BR /&gt;726 N(ELEV)-NMISS(ELEV) as ELEVCOUNT,&lt;BR /&gt;727 AVG(CASE ELEV WHEN 9999 THEN NULL ELSE ELEV END) as ELEV,&lt;BR /&gt;728 N(TEMP)-NMISS(TEMP) as TEMPCOUNT,&lt;BR /&gt;729 AVG(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as AVGTEMP,&lt;BR /&gt;730 RANGE(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as RANGETEMP,&lt;BR /&gt;731 MAX(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as HITEMP,&lt;BR /&gt;732 MIN(CASE TEMP WHEN 9999 THEN NULL ELSE TEMP END)/10 as LOTEMP,&lt;BR /&gt;733 N(PRESSURE)-NMISS(PRESSURE) as PRESSURECOUNT,&lt;BR /&gt;734 AVG(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as AVGPRESSURE,&lt;BR /&gt;735 MAX(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as HIPRESSURE,&lt;BR /&gt;736 MIN(CASE PRESSURE WHEN 99999 THEN NULL ELSE PRESSURE END)/10 as LOPRESSURE&lt;BR /&gt;737 from "D:\WeatherandZipFiles\COVERNUMERIC.sas7bdat"&lt;BR /&gt;738 group by USAF, WBAN, LAT, LONG, year, month, day;&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The RANGE summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: The AVG summary function requires a numeric argument.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: Result of WHEN clause 2 is not the same data type as the preceding results.&lt;BR /&gt;ERROR: Expression using division (/) requires numeric types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: NULL.&lt;BR /&gt;739 quit;&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;real time 0.02 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;740 run;&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 14:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640955#M21795</guid>
      <dc:creator>CJRPHD</dc:creator>
      <dc:date>2020-04-18T14:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640956#M21796</link>
      <description>&lt;P&gt;So you have your answer:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;ERROR: The following columns were not found in the contributing tables: NULL.&lt;/SPAN&gt;"&lt;/P&gt;
&lt;P&gt;I don't remember which&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;'s maxim it was, but I'm guessing like first: "Read the log"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are using NULL and SQL doesn't understand it as null value, use period (.) instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 14:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640956#M21796</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-04-18T14:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640957#M21797</link>
      <description>&lt;P&gt;Ok, this fixed the problem of computations (I will say I had the . originally in my code) but my "count" function wasn't properly recognizing the missing values so I tried null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count only non-missing values. Is they way I have it in the code incorrect?:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;N(PRESSURE)-NMISS(PRESSURE) as PRESSURECOUNT&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 15:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640957#M21797</guid>
      <dc:creator>CJRPHD</dc:creator>
      <dc:date>2020-04-18T15:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640959#M21798</link>
      <description>&lt;P&gt;I know why, I don't know why I didn't realise it earlier. PRESSURE still has the missing values as 99999, that's why my count code isn't working, because it is working. Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 18 Apr 2020 15:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/640959#M21798</guid>
      <dc:creator>CJRPHD</dc:creator>
      <dc:date>2020-04-18T15:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating Averages of missing values in SQL</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/641532#M21831</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't remember which&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;'s maxim it was, but I'm guessing like first: "Read the log"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actually, it's the second. The first is "Read the Documentation".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But we also have a violation of another maxim here, #34: "Work in Steps". By not building the SQL peacemeal, element by element, the OP created code with so many ERROR messages at once that the most important one was kind of "drowned out" and needed expert's eyes to be discovered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We also see a violation of Maxim 12, "Make it Look Nice".&lt;/P&gt;
&lt;P&gt;There is no consistent use of uppercase/lowercase, in fact most of the code is "shouting at the compiler", which makes it hard to read in the first place. There is no indentation, no use of blanks to separate words and operators, and complex elements like the case blocks are kept in one line, making it hard to see the branches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bottom line: this is an example for "how not to do it". That the code fails in a rather spectacular way should not come as a surprise.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 07:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculating-Averages-of-missing-values-in-SQL/m-p/641532#M21831</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-04-21T07:04:33Z</dc:date>
    </item>
  </channel>
</rss>

