BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bldudley
Obsidian | Level 7

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:

  1.          i)  Include in your table only the variables:  Gender and Age
  2.         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;
61
62 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 seconds
cpu time 0.01 seconds
 
67
68 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
81
 
Thanks, in advance for your help!
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

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

bldudley
Obsidian | Level 7

Thank you for your help!

Reeza
Super User

@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:

  1.          i)  Include in your table only the variables:  Gender and Age
  2.         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;
61
62 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 seconds
cpu time 0.01 seconds
 
67
68 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
81
 
Thanks, in advance for your help!

 

Reeza
Super User

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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 9752 views
  • 0 likes
  • 3 in conversation