<?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: How to mean values by a variable within sql in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819634#M34757</link>
    <description>&lt;P&gt;Do you really need dataset2? Do you really need PROC MEANS to make a printout if you are already making a dataset?&lt;/P&gt;
&lt;P&gt;Assuming that test_run only has integer values use IN operator for it also might be faster (depending on how DATASET1 is stored).&lt;/P&gt;
&lt;P&gt;Try doing it in one step instead of three.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=dataset1 NOPRINT nway;
  where subjectid in (&amp;amp;sb)
    and site in (&amp;amp;site)
    and test_run in (1 2 3 4 5)
  ;
  class subjectid site;
  var var1;
  output out=output1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2022 14:22:23 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-22T14:22:23Z</dc:date>
    <item>
      <title>How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819622#M34752</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a numeric variable (var1) and I am trying to compute the mean of this value based on two variables - subjectID and siteID - but only for specific values of a third variable, test_run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In particular, I only want to calculate the mean of var1 for test_run = 1-5. I want to do this for each subject and each site. I have a list of subjects (&amp;amp;sb) and sites (&amp;amp;site).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far I have this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table dataset2 as
select *
from dataset1
where subjectid in (&amp;amp;sb) and site in (&amp;amp;site) and 1 le test_run le 5;
quit;&lt;BR /&gt;&lt;BR /&gt;proc sort data=dataset2;&lt;BR /&gt;by subjectid site;&lt;BR /&gt;run;

proc means data=dataset2;
by subjectid site;
var var1;
output out=output1;
run;&lt;/PRE&gt;
&lt;P&gt;However these two steps take a very long time. I was wondering if there was a way of calculating this mean of var1 for 1&amp;lt;=testrun&amp;lt;=5 in the initial SQL call?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 13:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819622#M34752</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-06-22T13:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819628#M34754</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/426087"&gt;@linlin87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;However these two steps take a very long time. I was wondering if there was a way of calculating this mean of var1 for 1&amp;lt;=testrun&amp;lt;=5 in the initial SQL call?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"very long time" can mean anything, depending on the size of the data and the hardware, this could run some time. Please post the complete log of the steps shown with option fullstimer active.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 14:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819628#M34754</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-06-22T14:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819630#M34755</link>
      <description>I would post the log, but 9/10 times SAS ends up crashing</description>
      <pubDate>Wed, 22 Jun 2022 14:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819630#M34755</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-06-22T14:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819633#M34756</link>
      <description>&lt;P&gt;How large is the data set?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 14:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819633#M34756</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-22T14:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819634#M34757</link>
      <description>&lt;P&gt;Do you really need dataset2? Do you really need PROC MEANS to make a printout if you are already making a dataset?&lt;/P&gt;
&lt;P&gt;Assuming that test_run only has integer values use IN operator for it also might be faster (depending on how DATASET1 is stored).&lt;/P&gt;
&lt;P&gt;Try doing it in one step instead of three.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=dataset1 NOPRINT nway;
  where subjectid in (&amp;amp;sb)
    and site in (&amp;amp;site)
    and test_run in (1 2 3 4 5)
  ;
  class subjectid site;
  var var1;
  output out=output1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2022 14:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819634#M34757</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-22T14:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819647#M34760</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=dataset1(where=(subjectid in (&amp;amp;sb) and site in (&amp;amp;site) and 1 le test_run le 5)) nway;
class subjectid site;
var var1;
output out=output1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jun 2022 14:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819647#M34760</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-22T14:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to mean values by a variable within sql</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819649#M34762</link>
      <description>Yes it does only have integer values. Thanks Tom I will try this and let you know how it goes</description>
      <pubDate>Wed, 22 Jun 2022 14:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-mean-values-by-a-variable-within-sql/m-p/819649#M34762</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-06-22T14:49:23Z</dc:date>
    </item>
  </channel>
</rss>

