<?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: proc means (where and in operator). in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/631127#M186939</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310302"&gt;@xoxozav_1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;STRONG&gt;Hi,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I am struggling to generate different groups in proc means. I am trying to generate weekly average temperature groups using id variable and IN operator, and then get their average of each group.&lt;/P&gt;
&lt;P&gt;I developed the following syntax, but something is wrong. Could someone help me find what the mistake is?&lt;/P&gt;
&lt;P&gt;thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;This is my syntax :&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data= id80_00_20a;&lt;BR /&gt;where id (in (1,2,3,4,5,6, 7))=1;&lt;BR /&gt;where id (in (8,9,10,11,12,13,14, 15))=2 ;&lt;BR /&gt;where id (in (16,17,18,19,20,21,22,23))=3;&lt;BR /&gt;where id (in (24,25,26,27,28,29,30, 31))=4;&lt;BR /&gt;class id;&lt;BR /&gt;var avg1 avg2 avg3 ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;This is what the log page says:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73 proc means data= id80_00_20a;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 where id (in (1,2,3,4,5,6, 7))=1;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 where id (in (8,9,10,11,12,13,14, 15))=2 ;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 where id (in (16,17,18,19,20,21,22,23))=3;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 where id (in (24,25,26,27,28,29,30, 31))=4;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78 class id;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 var avg1 avg2 avg3 ;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;80 run;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If by any chance you had an actual date value for each record you could use a FORMAT to get values by week, depending on your "week" definiton. SAS uses 3 different appearances look at WEEKU WEEKV and WEEKW for the differences in starting day of the week and cross year behavior. This shows data that crosses a year boundary with a 2 digit year and the week indicator.&lt;/P&gt;
&lt;PRE&gt;data have;
   do date='14Jul2018'd to '05Mar2019'd;
      randomvalue = 100*(rand('uniform'));
      output;
   end;
run;

proc summary data=have nway ;
   class date;
   format date weekv5.;
   var randomvalue;
   output out=work.summary mean=;
run;&lt;/PRE&gt;
&lt;P&gt;You could create a nicer format for appearance using Proc Format.&lt;/P&gt;
&lt;P&gt;An advantage of the DATE plus format is that you can create other summary groups just changing the format. YYMM would give a year/month summary, YYQ would give a year/quarter summary, YEAR would give a calendar year summary, MONTH would give a calendar month summary across years and more with other formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or starting with a date you could create custome intervals with the INTNX function to create a date representative of LOTS of things.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Mar 2020 22:45:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-03-10T22:45:10Z</dc:date>
    <item>
      <title>proc means (where and in operator).</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/630774#M186781</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I am struggling to generate different groups in proc means. I am trying to generate weekly average temperature groups using id variable and IN operator, and then get their average of each group.&lt;/P&gt;&lt;P&gt;I developed the following syntax, but something is wrong. Could someone help me find what the mistake is?&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is my syntax :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc means data= id80_00_20a;&lt;BR /&gt;where id (in (1,2,3,4,5,6, 7))=1;&lt;BR /&gt;where id (in (8,9,10,11,12,13,14, 15))=2 ;&lt;BR /&gt;where id (in (16,17,18,19,20,21,22,23))=3;&lt;BR /&gt;where id (in (24,25,26,27,28,29,30, 31))=4;&lt;BR /&gt;class id;&lt;BR /&gt;var avg1 avg2 avg3 ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This is what the log page says:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;73 proc means data= id80_00_20a;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;74 where id (in (1,2,3,4,5,6, 7))=1;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;75 where id (in (8,9,10,11,12,13,14, 15))=2 ;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;76 where id (in (16,17,18,19,20,21,22,23))=3;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;77 where id (in (24,25,26,27,28,29,30, 31))=4;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;78 class id;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;79 var avg1 avg2 avg3 ;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;80 run;&lt;/DIV&gt;</description>
      <pubDate>Mon, 09 Mar 2020 23:35:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/630774#M186781</guid>
      <dc:creator>xoxozav_1</dc:creator>
      <dc:date>2020-03-09T23:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc means (where and in operator).</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/630788#M186784</link>
      <description>&lt;P&gt;The syntax for IN is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value in (...list...)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it returns a boolean results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not make a format?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
value idgroup
 1-7='Group 1'
 8-15='Group 2'
16-23='Group 3'
24-31='Group 4'
;
run;

proc means data= id80_00_20a;
  class id;
  var avg1 avg2 avg3 ;
  format id idgrp.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 02:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/630788#M186784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-10T02:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: proc means (where and in operator).</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/630789#M186785</link>
      <description>&lt;P&gt;1.&amp;nbsp; A where clause is used to subset a table.&lt;/P&gt;
&lt;P&gt;Here you have 4 clauses, so the last one supersedes the others.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; It seems that you want to change the value of ID.&lt;/P&gt;
&lt;P&gt;A where clause does not do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. The syntax you use is invalid. This syntax is valid:&lt;/P&gt;
&lt;P&gt;where ID in (1,2,3,4,5,6,7) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 02:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/630789#M186785</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-10T02:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc means (where and in operator).</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/631127#M186939</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310302"&gt;@xoxozav_1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;STRONG&gt;Hi,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I am struggling to generate different groups in proc means. I am trying to generate weekly average temperature groups using id variable and IN operator, and then get their average of each group.&lt;/P&gt;
&lt;P&gt;I developed the following syntax, but something is wrong. Could someone help me find what the mistake is?&lt;/P&gt;
&lt;P&gt;thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;This is my syntax :&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc means data= id80_00_20a;&lt;BR /&gt;where id (in (1,2,3,4,5,6, 7))=1;&lt;BR /&gt;where id (in (8,9,10,11,12,13,14, 15))=2 ;&lt;BR /&gt;where id (in (16,17,18,19,20,21,22,23))=3;&lt;BR /&gt;where id (in (24,25,26,27,28,29,30, 31))=4;&lt;BR /&gt;class id;&lt;BR /&gt;var avg1 avg2 avg3 ;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;This is what the log page says:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73 proc means data= id80_00_20a;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 where id (in (1,2,3,4,5,6, 7))=1;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 where id (in (8,9,10,11,12,13,14, 15))=2 ;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 where id (in (16,17,18,19,20,21,22,23))=3;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77 where id (in (24,25,26,27,28,29,30, 31))=4;&lt;/DIV&gt;
&lt;DIV class="sasError"&gt;ERROR: Function IN requires a character expression as argument 1.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78 class id;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 var avg1 avg2 avg3 ;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;80 run;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If by any chance you had an actual date value for each record you could use a FORMAT to get values by week, depending on your "week" definiton. SAS uses 3 different appearances look at WEEKU WEEKV and WEEKW for the differences in starting day of the week and cross year behavior. This shows data that crosses a year boundary with a 2 digit year and the week indicator.&lt;/P&gt;
&lt;PRE&gt;data have;
   do date='14Jul2018'd to '05Mar2019'd;
      randomvalue = 100*(rand('uniform'));
      output;
   end;
run;

proc summary data=have nway ;
   class date;
   format date weekv5.;
   var randomvalue;
   output out=work.summary mean=;
run;&lt;/PRE&gt;
&lt;P&gt;You could create a nicer format for appearance using Proc Format.&lt;/P&gt;
&lt;P&gt;An advantage of the DATE plus format is that you can create other summary groups just changing the format. YYMM would give a year/month summary, YYQ would give a year/quarter summary, YEAR would give a calendar year summary, MONTH would give a calendar month summary across years and more with other formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or starting with a date you could create custome intervals with the INTNX function to create a date representative of LOTS of things.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 22:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-means-where-and-in-operator/m-p/631127#M186939</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-10T22:45:10Z</dc:date>
    </item>
  </channel>
</rss>

