For the 1st "Test your code" question in scenario case 10:
1. What is the number of observations where the variable Type is Sedan?
The answer is showing obs:262.
However, I have obs:405.
Is it because the source data updated or I missed any step?
Thanks in advanced.
Thanks so much all !!
I think I misunderstood the question.
I think the question is asking the total number of observations where the variable Type is Sedan.
Not the number of observations where the variable type is sedan that With Average MPG Over 40.
To be more detail, i will provide the question and the code from answer key below.
Here is the question:
Open the ehs02 program from the EHS folder and correct the errors in the program below.
Example Code 2 ehs02 Program: Fix the Errors
work.mycars;
set sashelp.cars;
AvgMPG=mean(mpg_city, mpg_highway);
run;
title 'Cars With Average MPG Over 40';
proc print data=work.mycars
var make model type avgmpg;
where AvgMPG>40;
run;
title 'Average MPG by Car Type';
proc means data=work.mycars avg min max maxdec=1;
var avgmpg;
class type;
run;
title;
Test Your Code:
1. What is the number of observations where the variable Type is Sedan?
2. How many observations are printed to the report titled, “Cars With Average MPG Over 40”?
Objectives Accomplished:
• Identify the characteristics of SAS statements.
• Define SAS syntax rules and identify common syntax errors such as misspelled keywords, unmatched quotation marks,
missing semicolons, and invalid options.
• Use the log to help diagnose syntax errors in a given program.
---------------------------------------------------------------------------------------------
below is the code from the answer keys:
data work.mycars;
set sashelp.cars;
AvgMPG=mean(mpg_city, mpg_highway);
run;
title "Cars with Average MPG Over 40";
proc print data=work.mycars;
var make model type avgmpg;
where AvgMPG>40;
run;
title "Average MPG by Car Type";
proc means data=work.mycars mean min max maxdec=1;
var avgmpg;
class type;
run;
title;
@Teeleaf wrote:
For the 1st "Test your code" question in scenario case 10:
1. What is the number of observations where the variable Type is Sedan?
The answer is showing obs:262.
However, I have obs:405.
Is it because the source data updated or I missed any step?
Thanks in advanced.
Then, most likely something is wrong with your code. In sashelp.cars are only 262 obs with type = "Sedan".
And only 428 total observations in SASHELP.CARS.
At a minimum You need to show 1) any code used to create the data set you summarized and 2) the code used for the summary.
Thanks so much all !!
I think I misunderstood the question.
I think the question is asking the total number of observations where the variable Type is Sedan.
Not the number of observations where the variable type is sedan that With Average MPG Over 40.
To be more detail, i will provide the question and the code from answer key below.
Here is the question:
Open the ehs02 program from the EHS folder and correct the errors in the program below.
Example Code 2 ehs02 Program: Fix the Errors
work.mycars;
set sashelp.cars;
AvgMPG=mean(mpg_city, mpg_highway);
run;
title 'Cars With Average MPG Over 40';
proc print data=work.mycars
var make model type avgmpg;
where AvgMPG>40;
run;
title 'Average MPG by Car Type';
proc means data=work.mycars avg min max maxdec=1;
var avgmpg;
class type;
run;
title;
Test Your Code:
1. What is the number of observations where the variable Type is Sedan?
2. How many observations are printed to the report titled, “Cars With Average MPG Over 40”?
Objectives Accomplished:
• Identify the characteristics of SAS statements.
• Define SAS syntax rules and identify common syntax errors such as misspelled keywords, unmatched quotation marks,
missing semicolons, and invalid options.
• Use the log to help diagnose syntax errors in a given program.
---------------------------------------------------------------------------------------------
below is the code from the answer keys:
data work.mycars;
set sashelp.cars;
AvgMPG=mean(mpg_city, mpg_highway);
run;
title "Cars with Average MPG Over 40";
proc print data=work.mycars;
var make model type avgmpg;
where AvgMPG>40;
run;
title "Average MPG by Car Type";
proc means data=work.mycars mean min max maxdec=1;
var avgmpg;
class type;
run;
title;
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.