<?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 in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873199#M38720</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441639"&gt;@Sammy_G&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Define variables using a by statement on SAS OnDemand for academics&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If this is supposed to be an instruction from some sort of teacher I would find another class. The only variables "defined" with a BY statement are some automatic variables SAS creates in a data step to indicate if a particular observation is the the first or last of a given variable for a combination of variables on a BY statement. I might accept something like "Create variables to use later on a BY statement" but not as phrased.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What the BY statement does is attempt to do the same operations for each level of a given by variable or combination. Typically that requires sorting the data into that order using Proc Sort.&lt;/P&gt;
&lt;P&gt;Consider the SASHELP.CLASS data set that you should have available as an example. Suppose that we want to get summary statistics for the student weight and height variable By sex.&lt;/P&gt;
&lt;PRE&gt;Proc sort data=sashelp.class out=work.class;
   by sex;
run;

proc means data=work.class n mean min max std;
   by sex;
   var height weight;
run;&lt;/PRE&gt;
&lt;P&gt;This creates a summary for Sex=F and another for Sex=M. This what BY does, process groups of observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2023 15:46:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-05-01T15:46:03Z</dc:date>
    <item>
      <title>Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873126#M38703</link>
      <description>Define variables using a by statement on SAS OnDemand for academics&lt;BR /&gt;&lt;BR /&gt;libname patients '/home/u63367626/PATIENTS';&lt;BR /&gt;data patients.patt1;&lt;BR /&gt;set patt2;&lt;BR /&gt;format dob1 date9.;&lt;BR /&gt;&lt;BR /&gt;dob=compress(cat(month,'/',day,'/',year));&lt;BR /&gt;dob1=input(dob,mmddyy10.);&lt;BR /&gt;&lt;BR /&gt;age = yrdif(dob1,'01jan2023'd)/365;&lt;BR /&gt;run;&lt;BR /&gt;output;&lt;BR /&gt;=2;&lt;BR /&gt;output;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/*evaluating the statistical parameters for age*/&lt;BR /&gt;&lt;BR /&gt;proc sort data=patients.patt1;&lt;BR /&gt;by ;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=patients.patt1;&lt;BR /&gt;variables age;&lt;BR /&gt;output out= agestsatz;&lt;BR /&gt;by ;&lt;BR /&gt;run;</description>
      <pubDate>Mon, 01 May 2023 10:36:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873126#M38703</guid>
      <dc:creator>Sammy_G</dc:creator>
      <dc:date>2023-05-01T10:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873135#M38706</link>
      <description>&lt;P&gt;What is your question?&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 11:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873135#M38706</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-01T11:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873140#M38710</link>
      <description>What does the BY statement mean when finding a variable (age) using Proc Means, the course I’m taking stated it and I have no idea what it means</description>
      <pubDate>Mon, 01 May 2023 11:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873140#M38710</guid>
      <dc:creator>Sammy_G</dc:creator>
      <dc:date>2023-05-01T11:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873142#M38712</link>
      <description>&lt;P&gt;The code where there is no variable name(s) following BY, thusly&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does absolutely nothing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there were variable names after the BY, then this will have an impact, which you can read about in the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p1o0q4jmbtp52hn13yrk7umoqo2t.htm" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 11:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873142#M38712</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-01T11:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873153#M38715</link>
      <description>&lt;P&gt;You can see some sample output using BY statement in this paper:&amp;nbsp;&lt;A href="https://www.lexjansen.com/nesug/nesug08/ff/ff06.pdf" target="_blank"&gt;https://www.lexjansen.com/nesug/nesug08/ff/ff06.pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 12:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873153#M38715</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2023-05-01T12:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873161#M38717</link>
      <description>&lt;P&gt;This is not addressed to your question, but the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;age = yrdif(dob1,'01jan2023'd)/365;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;doesn't make sense.&amp;nbsp; Since the YRDIF function calculates the &lt;EM&gt;&lt;STRONG&gt;number of years&lt;/STRONG&gt;&lt;/EM&gt; between dob1 and jan 1, 2023, there is no reason to divide that result by 365.&amp;nbsp; What the code above produces is "number of 365-year intervals" between the dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's true that you can tell yrdif what year-calibration (to support various conventions in finance) you want to use, and perhaps that's what you wanted to do (see discussion of the &lt;EM&gt;&lt;STRONG&gt;basis&lt;/STRONG&gt;&lt;/EM&gt; argument in&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1pmmr2dtec32an1vbsqmm3abil5.htm" target="_self"&gt;YRDIF Function&lt;/A&gt;). But if you use this argument, then it must be the 3rd entry &lt;EM&gt;&lt;STRONG&gt;inside the parentheses&lt;/STRONG&gt;&lt;/EM&gt;, not outside the parentheses.&amp;nbsp; And as a character argument, it will have to be in quotes.&amp;nbsp; In your case, the likely basis would be "age", as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;age = yrdif(dob1,'01jan2023'd,'age');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And even that is unnecessary, since 'age' is the default basis.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 13:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873161#M38717</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-01T13:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873199#M38720</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441639"&gt;@Sammy_G&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Define variables using a by statement on SAS OnDemand for academics&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If this is supposed to be an instruction from some sort of teacher I would find another class. The only variables "defined" with a BY statement are some automatic variables SAS creates in a data step to indicate if a particular observation is the the first or last of a given variable for a combination of variables on a BY statement. I might accept something like "Create variables to use later on a BY statement" but not as phrased.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What the BY statement does is attempt to do the same operations for each level of a given by variable or combination. Typically that requires sorting the data into that order using Proc Sort.&lt;/P&gt;
&lt;P&gt;Consider the SASHELP.CLASS data set that you should have available as an example. Suppose that we want to get summary statistics for the student weight and height variable By sex.&lt;/P&gt;
&lt;PRE&gt;Proc sort data=sashelp.class out=work.class;
   by sex;
run;

proc means data=work.class n mean min max std;
   by sex;
   var height weight;
run;&lt;/PRE&gt;
&lt;P&gt;This creates a summary for Sex=F and another for Sex=M. This what BY does, process groups of observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 15:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873199#M38720</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-01T15:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proc means</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873200#M38721</link>
      <description>&lt;PRE&gt;libname patients '/home/u63367626/PATIENTS';


data patients.patt1;
set patt2;
format dob1 date9.;

*removes spaces and adds / between values. Easier to use the MDY function;
dob=compress(cat(month,'/',day,'/',year));
dob1=input(dob,mmddyy10.);

*incorrect calculation of age, should be age = yrdif(dob1, '01jan2023'd, dob1);
age = yrdif(dob1,'01jan2023'd)/365;
*ends current data step;
run;

*outside of data step - does nothing/error;
output;
*outside of data step - does nothing/error;
=2;
*outside of data step - does nothing/error;
output;
*outside of data step - does nothing/error;
run;


/*evaluating the statistical parameters for age*/

proc sort data=patients.patt1;
*outside of data step - does nothing/error;
by ;
run;

proc means data=patients.patt1;
variables age; *usually see var age not the full word variables;
output out= agestsatz;
by ; *no variable specified to break up the analysis;
run;&lt;/PRE&gt;
&lt;P&gt;See comments on your code.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 15:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Proc-means/m-p/873200#M38721</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-01T15:51:21Z</dc:date>
    </item>
  </channel>
</rss>

