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

Showing results for

Find a Community

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-18-2017 01:08 PM

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!

Accepted Solutions

Solution

05-20-2017
01:14 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Mila

05-18-2017 01:13 PM

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.

All Replies

Solution

05-20-2017
01:14 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Mila

05-18-2017 01:13 PM

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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Mila

05-18-2017 01:17 PM

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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Mila

05-18-2017 01:40 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PaigeMiller

05-20-2017 01:15 AM

Thank you for your response, it turns out my code worked exactly as intended - i am not sure why it was collapsing the data int he begiining. But upon clearing sas and re-running my code- it turned out well. Thank you!