BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
twocents
Calcite | Level 5
I am trying to run descriptive statistics using PROC MEANS in SAS. However I am getting that my inserted variables are not match type prescribed. Nothing I am doing is working. What am i doing wrong. Also, I get this error for all 14 variables and I am trying to run descriptive statistics on all 14 variables. 
 
filename winedata '/folders/myfolders/390 hw/wine.data.txt';
data wine;
infile winedata DELIMITER=',';
input iden $ Alco $ Mali $ Ash $ Alca $ Magn $ Tota $ Flav $ Nonf $ proa $ Colo $ Hue $ OD28 $ Prol $;    
TITLE 'Wine Summary Data';
run;
proc print data=wine;
run;
proc means data=wine n mean;    
by iden;
var iden Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;
run; 
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@twocents wrote:
I am trying to run descriptive statistics using PROC MEANS in SAS. However I am getting that my inserted variables are not match type prescribed. Nothing I am doing is working. What am i doing wrong. Also, I get this error for all 14 variables and I am trying to run descriptive statistics on all 14 variables. 
 
filename winedata '/folders/myfolders/390 hw/wine.data.txt';
data wine;
infile winedata DELIMITER=',';
input iden $ Alco $ Mali $ Ash $ Alca $ Magn $ Tota $ Flav $ Nonf $ proa $ Colo $ Hue $ OD28 $ Prol $;    
TITLE 'Wine Summary Data';
run;
proc print data=wine;
run;
proc means data=wine n mean;    
by iden;
var iden Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;
run; 

Please use a code box when inserting code, it makes it easier to read and copy/paste. As others have mentioned, the issue is with the $ sign, because that tells SAS to read it in as a character variable. And you can't calculate the mean on a set of characters. 

 

data wine;
infile winedata DELIMITER=',';
input iden $ Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;  
run;



TITLE 'Wine Detail Data';
proc print data=wine;
run;

TITLE 'Wine Summary Statistics';
proc means data=wine n mean;    
by iden; *is the data sorted already? If not you may get an error here as well;
var iden Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;
run; 

Things in read are ones I've changed or re-ordered. 

Make sure you data is sorted, otherwise your BY statement won't work properly. 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

You cannot take the mean of a character string.

Why did you define the variables as character in your INPUT statement if you want to use them as numbers?

heffo
Pyrite | Level 9

In your imput statement you define all variables as strings. Proc means can only deal with numeric variables. Remove all the $ signs in the input statement and it should hopefully work. 

Reeza
Super User

@twocents wrote:
I am trying to run descriptive statistics using PROC MEANS in SAS. However I am getting that my inserted variables are not match type prescribed. Nothing I am doing is working. What am i doing wrong. Also, I get this error for all 14 variables and I am trying to run descriptive statistics on all 14 variables. 
 
filename winedata '/folders/myfolders/390 hw/wine.data.txt';
data wine;
infile winedata DELIMITER=',';
input iden $ Alco $ Mali $ Ash $ Alca $ Magn $ Tota $ Flav $ Nonf $ proa $ Colo $ Hue $ OD28 $ Prol $;    
TITLE 'Wine Summary Data';
run;
proc print data=wine;
run;
proc means data=wine n mean;    
by iden;
var iden Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;
run; 

Please use a code box when inserting code, it makes it easier to read and copy/paste. As others have mentioned, the issue is with the $ sign, because that tells SAS to read it in as a character variable. And you can't calculate the mean on a set of characters. 

 

data wine;
infile winedata DELIMITER=',';
input iden $ Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;  
run;



TITLE 'Wine Detail Data';
proc print data=wine;
run;

TITLE 'Wine Summary Statistics';
proc means data=wine n mean;    
by iden; *is the data sorted already? If not you may get an error here as well;
var iden Alco Mali Ash Alca Magn Tota Flav Nonf proa Colo Hue OD28 Prol;
run; 

Things in read are ones I've changed or re-ordered. 

Make sure you data is sorted, otherwise your BY statement won't work properly. 

twocents
Calcite | Level 5

Thank you so much. I am still learning everything with SAS so I apologize for my formatting. 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1211 views
  • 0 likes
  • 4 in conversation