BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

What is wrong with this code to calculate mean and std?

error:

 

ERROR: Alphabetic prefixes for enumerated variables (X1_Sum-X12_sum) are different.
ERROR 71-185: The MEAN function call does not have enough arguments.

data wanted;
set have;
X1_avg12=mean(OF X1_sum-X12_SUM);
X1_std12=std(OF X1_sum-X12_SUM);
Run;
5 REPLIES 5
ballardw
Super User

The SUM you have at the end of the variable names means that they are not sequentially numbered. List like x1-x12 have to end in numbers (and have no gaps in the numbering).

Reeza
Super User

You have this:

X1_SUM-X12_SUM where the index is not the last part of the variable.

 

If it was this, it would work as expected:

 

X_SUM1-X_SUM12

 

You can try the format of firstVariable--secondVariable which will select all variables in between the first variable and the last variable

 

data wanted;
set have;

X1_avg12 = mean(OF X1_sum--X12_SUM);
X1_std12 = std(OF X1_sum--X12_SUM);

Run;

 

 

Here is a reference that illustrates how to refer to variables and datasets in a short cut list:
https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html

 


@Ronein wrote:

Hello

What is wrong with this code to calculate mean and std?

error:

 

ERROR: Alphabetic prefixes for enumerated variables (X1_Sum-X12_sum) are different.
ERROR 71-185: The MEAN function call does not have enough arguments.

data wanted;
set have;
X1_avg12=mean(OF X1_sum-X12_SUM);
X1_std12=std(OF X1_sum-X12_SUM);
Run;

 

Tom
Super User Tom
Super User

@Ronein wrote:

Hello

What is wrong with this code to calculate mean and std?

error:

 

ERROR: Alphabetic prefixes for enumerated variables (X1_Sum-X12_sum) are different.
ERROR 71-185: The MEAN function call does not have enough arguments.

data wanted;
set have;
X1_avg12=mean(OF X1_sum-X12_SUM);
X1_std12=std(OF X1_sum-X12_SUM);
Run;

What's wrong?  The problem is the way that you named those "sum" variables.   Can you back up a step and change the code that is creating X1_SUM and instead name it something like SUM_X1 or X_SUM1 where the numeric suffix is an actual suffix?

AMSAS
SAS Super FREQ

Here's the link to the documentation on SAS Variable Lists 

You might want to try using a Variable Name Range List. Just make sure you are real careful.

Here's an example:

data got ;
	infile cards ;
	input x1_sum x2_sum x5_sum x3_sum ;
	mySum=sum(of x1_sum--x5_sum) ;
	put _all_ ;
cards ;
1 2 3 4
2 3 4 5
3 4 5 6
;
run ;

And the SAS Log:

68   data got ;
69       infile cards ;
70       input x1_sum x2_sum x5_sum x3_sum ;
71       mySum=sum(of x1_sum--x5_sum) ;
72       put _all_ ;
73   cards ;

x1_sum=1 x2_sum=2 x5_sum=3 x3_sum=4 mySum=6 _ERROR_=0 _N_=1
x1_sum=2 x2_sum=3 x5_sum=4 x3_sum=5 mySum=9 _ERROR_=0 _N_=2
x1_sum=3 x2_sum=4 x5_sum=5 x3_sum=6 mySum=12 _ERROR_=0 _N_=3
NOTE: The data set WORK.GOT has 3 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


77   ;
78   run ;

Notice how it is summing only x1_sum, x2_sum and x5_sum and not including x3_sum, that's because it is summing the variables in the order they are created. 

Again be careful if you use this, as it could be confusing and easily broken if the code is changed.

PaigeMiller
Diamond | Level 26

All of these difficulties are avoided if you have a long data set instead of a wide data set. Such as ...

 

data have;
    input id x;
    cards;
1 243
2 333
3 87
...
;
proc summary data=have;
    var x;
    output out=want sum=sum stddev=s;
run;

and it's less typing. which means less chance for typographical errors or naming errors. and the code still works if you have a 13th data point (or a 14th data point or ...)

 

 

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 562 views
  • 0 likes
  • 6 in conversation