Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Computing means...without proc MEANS

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 05-18-2017 01:08 PM
(1450 views)

Hi there!

I am trying ot compute means across every row of data (say 3000) that i have in my dataset. There are 3000 rows and 50 columns - and the mean is looking ot average 8 of the 50 columns across 3000 lines.

Below is the code i have written, but it collapses the data into 1 average, which is not what i am looking for. How do i get it to average across 8 variables for each of the 3000 rows?

Would proc means work here? When i tried it, it appeared as though that would would collapse the data

**data** ccm_crsp_monthly4;

array x[**8**] DP_Rank PPE_Rank PS_Rank TPS_Rank CF_Rank TFO_Rank PSR_Rank DPS_Rank;

array y[**6**] DS_Rank RO_Rank PS_Rank TPS_Rank PR_Rank XPS_Rank;

SixVar=mean(of y[*]);

EightVar=mean(of x[*]);

Run;

More failed attempts - proc means:

**proc** **means** DATA=ccm_monthly;

class date permno;

var DS_Rank PPE_Rank PS_Rank TPS_Rank XS_Rank XRS_Rank;

output

out=cc_monthly4(drop=_TYPE_ _FREQ_) mean=SixVariable;

**run**;

Thsi should be a really simple things to do...lol!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You really should provide a small example data set and what the result for that example data should be.

Your comment "but it collapses the data into 1 average" is not very descriptive since the code you show would create 2 variables with the means of the two arrays for each row of data. If that isn't what you want then you need to show a very explicit example. The example need not include all 14 variables, probably the first 3 variables of each array and values that are not the same for each variable and row.

If you have a data then Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You really should provide a small example data set and what the result for that example data should be.

Your comment "but it collapses the data into 1 average" is not very descriptive since the code you show would create 2 variables with the means of the two arrays for each row of data. If that isn't what you want then you need to show a very explicit example. The example need not include all 14 variables, probably the first 3 variables of each array and values that are not the same for each variable and row.

If you have a data then Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Where is you Set Statement?

data ccm_crsp_monthly4;

array x[8] DP_Rank PPE_Rank PS_Rank TPS_Rank CF_Rank TFO_Rank PSR_Rank DPS_Rank;

array y[6] DS_Rank RO_Rank PS_Rank TPS_Rank PR_Rank XPS_Rank;

/* SET <lib.>dataset; */

SixVar=mean(of y[*]);

EightVar=mean(of x[*]);

Run;

data ccm_crsp_monthly4;

array x[8] DP_Rank PPE_Rank PS_Rank TPS_Rank CF_Rank TFO_Rank PSR_Rank DPS_Rank;

array y[6] DS_Rank RO_Rank PS_Rank TPS_Rank PR_Rank XPS_Rank;

/* SET <lib.>dataset; */

SixVar=mean(of y[*]);

EightVar=mean(of x[*]);

Run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Below is the code i have written, but it collapses the data into 1 average, which is not what i am looking for. How do i get it to average across 8 variables for each of the 3000 rows?

Sometimes words across the internet fail to have the intended meaning, I just don't understand this sentence, and it would be *extremely* helpful if you could show us an example of what this sentence really means.

But, in general, if you want to average numbers left-to-right (or right-to-left) within an observation, you need to use the MEAN function in a datastep.

If you want to average down columns, you can use PROC MEANS. The only way to get PROC MEANS to average right-to-left within a row is to first transpose the data set so that what used to be a row is now a column.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**SAS Innovate 2025** is scheduled for May 6-9 in Orlando, FL. Sign up to be **first to learn** about the agenda and registration!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Ready to level-up your skills? Choose your own adventure.