<?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 calculate mean across several variables in SAS? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550806#M152956</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried to do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile 'data set';&lt;/P&gt;
&lt;P&gt;input totsps totspm totspt totspw;&lt;/P&gt;
&lt;P&gt;avgsp = (totsps +totspm +totspt+totspw/4);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it creates a new variable but not a new output for avgsp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help... i feel like my input step may be wrong&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You attempted code is incorrect as it only divides the last variable totspq by 4.&lt;/P&gt;
&lt;P&gt;SAS makes this much easier with functions such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;avgsp = mean(totsps, totspm, totspt, totspw);&lt;/P&gt;
&lt;P&gt;Which will calculate the mean for a single row of data.&lt;/P&gt;
&lt;P&gt;If you need a mean across all of the rows of data then follow up with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc means data=want mean;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var avgsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2019 22:43:15 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-04-12T22:43:15Z</dc:date>
    <item>
      <title>How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550745#M152935</link>
      <description>&lt;P&gt;I tried to do&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;infile 'data set';&lt;/P&gt;&lt;P&gt;input totsps totspm totspt totspw;&lt;/P&gt;&lt;P&gt;avgsp = (totsps +totspm +totspt+totspw/4);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it creates a new variable but not a new output for avgsp.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help... i feel like my input step may be wrong&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 18:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550745#M152935</guid>
      <dc:creator>sasuser94</dc:creator>
      <dc:date>2019-04-12T18:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550755#M152938</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp; &amp;nbsp;Please post a sample of your input data and the expected output&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 19:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550755#M152938</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-12T19:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550773#M152943</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried to do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile 'data set';&lt;/P&gt;
&lt;P&gt;input totsps totspm totspt totspw;&lt;/P&gt;
&lt;P&gt;avgsp = (totsps +totspm +totspt+totspw/4);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it creates a new variable but not a new output for avgsp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help... i feel like my input step may be wrong&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;avgsp = ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you are indeed creating a new variable. I don't know what you mean by "new output for avgsp", please show us what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, that's the wrong formula for average.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 20:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550773#M152943</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-12T20:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550784#M152948</link>
      <description>&lt;P&gt;Do you want an average for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. The individual row - a value for each row&lt;/P&gt;
&lt;P&gt;2. For all rows, for all the different variables as one measurement, ie mean of totsps, spm, spt, spw - one number&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. For each variable across all rows - four numbers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect it's #2, but it's not clear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried to do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile 'data set';&lt;/P&gt;
&lt;P&gt;input totsps totspm totspt totspw;&lt;/P&gt;
&lt;P&gt;avgsp = (totsps +totspm +totspt+totspw/4);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it creates a new variable but not a new output for avgsp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help... i feel like my input step may be wrong&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 20:55:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550784#M152948</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-12T20:55:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550806#M152956</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried to do&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;infile 'data set';&lt;/P&gt;
&lt;P&gt;input totsps totspm totspt totspw;&lt;/P&gt;
&lt;P&gt;avgsp = (totsps +totspm +totspt+totspw/4);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but it creates a new variable but not a new output for avgsp.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please help... i feel like my input step may be wrong&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You attempted code is incorrect as it only divides the last variable totspq by 4.&lt;/P&gt;
&lt;P&gt;SAS makes this much easier with functions such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;avgsp = mean(totsps, totspm, totspt, totspw);&lt;/P&gt;
&lt;P&gt;Which will calculate the mean for a single row of data.&lt;/P&gt;
&lt;P&gt;If you need a mean across all of the rows of data then follow up with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc means data=want mean;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var avgsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2019 22:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550806#M152956</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-12T22:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550823#M152964</link>
      <description>Hello everyone-&lt;BR /&gt;&lt;BR /&gt;Thank you for your input. I am trying to get the average of 4 variables (totsps, totspm, totspt, totspw) and create a new variable called avgslp to get the average of the 4 days. I would like to do this for my entire data set.&lt;BR /&gt;Thank you</description>
      <pubDate>Sat, 13 Apr 2019 03:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550823#M152964</guid>
      <dc:creator>sasuser94</dc:creator>
      <dc:date>2019-04-13T03:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550833#M152969</link>
      <description>I don’t get any output when I run the code to create a new variable. I want to create a new variable “avgsp” by calculating the meaning across 4 variables (totsps, totspm, totspt, totspw).... every time I try to run code in sas it says errors and the new data set has missing values. I think it may have something to do with me trying to use ‘infile’ to tell sas what data set to use.</description>
      <pubDate>Sat, 13 Apr 2019 07:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550833#M152969</guid>
      <dc:creator>sasuser94</dc:creator>
      <dc:date>2019-04-13T07:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550835#M152971</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I don’t get any output when I run the code to create a new variable. I want to create a new variable “avgsp” by calculating the meaning across 4 variables (totsps, totspm, totspt, totspw).... every time I try to run code in sas it says errors and the new data set has missing values. I think it may have something to do with me trying to use ‘infile’ to tell sas what data set to use.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please post the log using the window opened by the {i} button.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: You know that the infile-statement read text-files, if you want to process a dataset you need the set-statement.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2019 09:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550835#M152971</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-13T09:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550838#M152973</link>
      <description>&lt;PRE&gt;DATA SLEEP2;
infile ':\AH data.xlsx';
AVGSLP = MEAN(TOTSPSUN, TOTSPMON, TOTSPTUE, TOTSPWED);
RUN;

PROC MEANS DATA = WORK.PRAPCRO1;
AVGSP = MEAN(TOTSPSUN, TOTSPMON, TOTSPTUE, TOTSPWED);
VAR AVGSP;
RUN;&lt;/PRE&gt;&lt;P&gt;how would i use a set statement?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2019 10:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550838#M152973</guid>
      <dc:creator>sasuser94</dc:creator>
      <dc:date>2019-04-13T10:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550842#M152974</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thank you for your input. I am trying to get the average of 4 variables (totsps, totspm, totspt, totspw) and create a new variable called avgslp to get the average of the 4 days. I would like to do this for my entire data set.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, it sure would be nice if you gave an example using a small example data set, because the above sentence can be interpreted in several ways.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2019 11:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550842#M152974</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-13T11:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550844#M152975</link>
      <description>So an example dataset is...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Totsps. Totspm. Totspt&lt;BR /&gt;1. 1 8&lt;BR /&gt;2 5 5&lt;BR /&gt;2. 8 7&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I’m looking to calculate the average of each row by creating a new variable avgslp&lt;BR /&gt;3&lt;BR /&gt;</description>
      <pubDate>Sat, 13 Apr 2019 11:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550844#M152975</guid>
      <dc:creator>sasuser94</dc:creator>
      <dc:date>2019-04-13T11:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550847#M152976</link>
      <description>&lt;P&gt;3 is not the "average of each row".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you really want the "average of each row", you would have three new values, one for each row.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2019 14:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550847#M152976</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-13T14:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550850#M152978</link>
      <description>&lt;P&gt;From that data the only operation I can think of that would result in 3 would be to count the number of observations.&lt;/P&gt;
&lt;P&gt;First get your data into a SAS dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Totsps Totspm Totspt ;
cards;
1 1 8
2 5 5
2 8 7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to make a new variable then create a new dataset by reading in the current dataset and doing something.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  tots_avg = mean(of totsps totspm totspt);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you have the average of those three variables on EACH observation.&lt;/P&gt;
&lt;PRE&gt;Obs    Totsps    Totspm    Totspt    tots_avg

 1        1         1         8       3.33333
 2        2         5         5       4.00000
 3        2         8         7       5.66667&lt;/PRE&gt;
&lt;P&gt;If you want the average across the whole dataset you can use PROC MEANS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;The MEANS Procedure

Variable    N            Mean         Std Dev         Minimum         Maximum
-----------------------------------------------------------------------------
Totsps      3       1.6666667       0.5773503       1.0000000       2.0000000
Totspm      3       4.6666667       3.5118846       1.0000000       8.0000000
Totspt      3       6.6666667       1.5275252       5.0000000       8.0000000
tots_avg    3       4.3333333       1.2018504       3.3333333       5.6666667
-----------------------------------------------------------------------------&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Apr 2019 17:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550850#M152978</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-13T17:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550887#M152997</link>
      <description>&lt;P&gt;Excel-files aren't datasets! Excel-files are read by proc import or by using a libname statement.Try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname source xlsx "b:/ah data.xlsx";

/* process file */

libname source clear;

/* or with proc import */
proc import datafile="b:/ah data.xlsx" dbms=xlsx out=work.have replace;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Apr 2019 15:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550887#M152997</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-04-14T15:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550943#M153015</link>
      <description>&lt;P&gt;1. You cannot really refer to an XLSX file like this. You first need to import it somehow. If you know the sheet name, this is pretty trivial. Use PROC IMPORT to import your Excel sheet first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Once you have it imported, your best bet is to reformat the data using proc transpsose and then use PROC MEANS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will import an xlsx file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import out=AHDATA file = 'path to xlsx file.xlsx' dbms=xlsx replace; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use PROC TRANSPOSE to flip your data.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use PROC MEANS to summarize your data&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/proc_means_basic.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264806"&gt;@sasuser94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;DATA SLEEP2;
infile ':\AH data.xlsx';
AVGSLP = MEAN(TOTSPSUN, TOTSPMON, TOTSPTUE, TOTSPWED);
RUN;

PROC MEANS DATA = WORK.PRAPCRO1;
AVGSP = MEAN(TOTSPSUN, TOTSPMON, TOTSPTUE, TOTSPWED);
VAR AVGSP;
RUN;&lt;/PRE&gt;
&lt;P&gt;how would i use a set statement?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Apr 2019 01:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/550943#M153015</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-15T01:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate mean across several variables in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/962762#M375197</link>
      <description>Best answer!!</description>
      <pubDate>Thu, 27 Mar 2025 04:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculate-mean-across-several-variables-in-SAS/m-p/962762#M375197</guid>
      <dc:creator>pixmmxie_</dc:creator>
      <dc:date>2025-03-27T04:33:46Z</dc:date>
    </item>
  </channel>
</rss>

