Hello,
I'm a student learning base SAS with university edition.
My instruction for this step is as follows:
4) Create a Means Table using Proc Means:
iii) Please interpret your Proc Means output by answering the following questions
4a) What is the mean age of a female in the "Under 30" age group?
4b) What is the mean age of a male in the "Over 50" age group?
The problem I'm having is that I keep getting this error on my last data step {proc mean}:
ERROR: Variable gender in list does not match type prescribed for this list.
My code and log are as follows:
libname RV '/folders/myfolders/Week 7'; /*Recall previous permanent dataset*/
data rv.RV_Market_Analysis; /*new dataset*/
set rv.rv_marketdo; /*previous dataset*/
run;
proc print data=rv.rv_market_analysis;
run;
Proc format;
value bracket 0-29='Under 30'
30-50='30-50'
50-100='Over 50';
run;
Data rv.RV_Market_Analysis;
set rv.RV_Market_Analysis;
label Age_Bracket = 'Age Bracket';
Age_Bracket = PUT(Age, bracket.);
run;
proc print data=rv.rv_market_analysis label;
run;
proc freq data=rv.rv_market_analysis;
format age bracket.;
tables age*gender;
run;
proc means data=rv.rv_market_analysis;
format age bracket.;
class age gender;
var age gender;
run;
You didn't show us your data, but it looks like you are trying to get the average of values like "M" and "F".
I think what you want for that last step is:
proc means data=rv.rv_market_analysis; class gender age_bracket; var age; run;
Art, CEO, AnalystFinder.com
You didn't show us your data, but it looks like you are trying to get the average of values like "M" and "F".
I think what you want for that last step is:
proc means data=rv.rv_market_analysis; class gender age_bracket; var age; run;
Art, CEO, AnalystFinder.com
Thank you for your help!
@bldudley wrote:
Hello,
I'm a student learning base SAS with university edition.
My instruction for this step is as follows:
4) Create a Means Table using Proc Means:
- i) Include in your table only the variables: Gender and Age
- ii) Format the Age variable using your age format in step 2.
iii) Please interpret your Proc Means output by answering the following questions
4a) What is the mean age of a female in the "Under 30" age group?
4b) What is the mean age of a male in the "Over 50" age group?
The problem I'm having is that I keep getting this error on my last data step {proc mean}:
ERROR: Variable gender in list does not match type prescribed for this list.My code and log are as follows:
libname RV '/folders/myfolders/Week 7'; /*Recall previous permanent dataset*/ data rv.RV_Market_Analysis; /*new dataset*/ set rv.rv_marketdo; /*previous dataset*/ run; proc print data=rv.rv_market_analysis; run; Proc format; value bracket 0-29='Under 30' 30-50='30-50' 50-100='Over 50'; run; Data rv.RV_Market_Analysis; set rv.RV_Market_Analysis; label Age_Bracket = 'Age Bracket'; Age_Bracket = PUT(Age, bracket.); run; proc print data=rv.rv_market_analysis label; run; proc freq data=rv.rv_market_analysis; format age bracket.; tables age*gender; run; proc means data=rv.rv_market_analysis; format age bracket.; class age gender; var age gender; run;
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;6162 proc means data=rv.rv_market_analysis;63 format age bracket.;64 class age gender/missing;65 var age gender;ERROR: Variable gender in list does not match type prescribed for this list.66 run;NOTE: The SAS System stopped processing this step because of errors.NOTE: PROCEDURE MEANS used (Total process time):real time 0.00 secondscpu time 0.01 seconds6768 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;81Thanks, in advance for your help!
See the comments in the code below.
libname RV '/folders/myfolders/Week 7'; /*Recall previous permanent dataset*/
*This step is useless, you're creating a new dataset that's identical to the old one; data rv.RV_Market_Analysis; /*new dataset*/ set rv.rv_marketdo; /*previous dataset*/ run;
*This doesn't add anything to your project or answer so you don't need this step. Open the dataset instead of printing it; proc print data=rv.rv_market_analysis; run; Proc format; value bracket 0-29='Under 30' 30-50='30-50' 50-100='Over 50'; run;
/*This is bad coding style the SET and DATA statement should have different names.
When you use this type of coding it becomes harder to determine where an error occurred
or when the mistake is. It also means you have to re-run your whole code every time rather than just the latest steps.
Change the SET statement to be the data set from the first data step
*/
Data rv.RV_Market_Analysis; set rv.RV_Market_Analysis; label Age_Bracket = 'Age Bracket'; Age_Bracket = PUT(Age, bracket.); run;
*If you're going to use PRINT at least limit it, so you don't get the full listing
ADD (obs=20) after the data set name;
proc print data=rv.rv_market_analysis label; run; proc freq data=rv.rv_market_analysis; format age bracket.; tables age*gender; run;
/*It's rarely likely to have the CLASS and VAR statements have the same variables.
CLASS is for the variables that you want the analysis grouped by.
VAR is for the variables you want to have statistics, ie mean of variable in VAR.
*/ proc means data=rv.rv_market_analysis; format age bracket.; class age gender; var age gender; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.