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. 

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
  • 4 replies
  • 637 views
  • 0 likes
  • 4 in conversation