Help using Base SAS procedures

PROC SQL and PROC MEANS default rounding in output

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

PROC SQL and PROC MEANS default rounding in output

I would like to be able to explain the differences in the default rounding between different procedures.  For example, consider the following data set where we have three exam grades from 10 students, and I want to calculate the average grade for each exam.  This has been computed by both proc means and proc sql.

 

DATA grades;
INPUT name $ exam1 exam2 exam3;
DATALINES;
Shannon 96 82 83
Lex 92 81 68
Becky 92 75 73
Lora 94 65 70
Susan 91 77 85
Hunter 76 72 86
Ulric 98 71 80
Richann 90 60 60
Tim 97 94 100
Ronald . 77 60
;
RUN;

PROC MEANS DATA=grades;
VAR exam1 exam2 exam3;
RUN;

PROC SQL;
SELECT COUNT(exam1) AS n_exam1,
MEAN(exam1) AS ave_exam1,
COUNT(exam2) AS n_exam2,
MEAN(exam2) AS ave_exam2,
COUNT(exam3) AS n_exam3,
MEAN(exam3) AS ave_exam3
FROM grades;
QUIT;

When you use proc means, the output by default consistently rounds to seven decimal places.  However, when you use proc sql the output rounds to something that I guess is more related to significant digits or precision.  Could some one explain the default rounding more formally, especially for proc sql?


Accepted Solutions
Solution
3 weeks ago
SAS Employee
Posts: 115

Re: PROC SQL and PROC MEANS default rounding in output

[ Edited ]

Tables have templates.  Templates control what the output looks like.  That said, sometimes templates don't specify everything.  The information can come from other sources such as directly from the procedure, from ODS, from message files (internal files that enable translation) and from dynamic variables.  Many templates are reasonably straight-forward.  The two you are asking about, not so much.  My test case below shows how to find the names of the templates and then display them.  That does not tell you much in this case, but ultimately, different formats are set by the different procedures.  That is not unusual. You can do an ODS output on those tables and run proc contents to see the actual formats.  I could go into way more detail, but we start getting into sausage-making type conversations.  If you want to control the format, you could create output data sets, set formats, and then use proc print.  You could do many other things as well.

DATA grades;
INPUT name $ exam1 exam2 exam3;
DATALINES;
Shannon 96 82 83
Lex 92 81 68
Becky 92 75 73
Lora 94 65 70
Susan 91 77 85
Hunter 76 72 86
Ulric 98 71 80
Richann 90 60 60
Tim 97 94 100
Ronald . 77 60
;
ods trace on;

PROC MEANS DATA=grades;
VAR exam1 exam2 exam3;
RUN;

PROC SQL;
SELECT COUNT(exam1) AS n_exam1,
MEAN(exam1) AS ave_exam1,
COUNT(exam2) AS n_exam2,
MEAN(exam2) AS ave_exam2,
COUNT(exam3) AS n_exam3,
MEAN(exam3) AS ave_exam3
FROM grades;
QUIT;

proc template;
source Base.SQL;
source base.summary;
quit;

 

View solution in original post


All Replies
Solution
3 weeks ago
SAS Employee
Posts: 115

Re: PROC SQL and PROC MEANS default rounding in output

[ Edited ]

Tables have templates.  Templates control what the output looks like.  That said, sometimes templates don't specify everything.  The information can come from other sources such as directly from the procedure, from ODS, from message files (internal files that enable translation) and from dynamic variables.  Many templates are reasonably straight-forward.  The two you are asking about, not so much.  My test case below shows how to find the names of the templates and then display them.  That does not tell you much in this case, but ultimately, different formats are set by the different procedures.  That is not unusual. You can do an ODS output on those tables and run proc contents to see the actual formats.  I could go into way more detail, but we start getting into sausage-making type conversations.  If you want to control the format, you could create output data sets, set formats, and then use proc print.  You could do many other things as well.

DATA grades;
INPUT name $ exam1 exam2 exam3;
DATALINES;
Shannon 96 82 83
Lex 92 81 68
Becky 92 75 73
Lora 94 65 70
Susan 91 77 85
Hunter 76 72 86
Ulric 98 71 80
Richann 90 60 60
Tim 97 94 100
Ronald . 77 60
;
ods trace on;

PROC MEANS DATA=grades;
VAR exam1 exam2 exam3;
RUN;

PROC SQL;
SELECT COUNT(exam1) AS n_exam1,
MEAN(exam1) AS ave_exam1,
COUNT(exam2) AS n_exam2,
MEAN(exam2) AS ave_exam2,
COUNT(exam3) AS n_exam3,
MEAN(exam3) AS ave_exam3
FROM grades;
QUIT;

proc template;
source Base.SQL;
source base.summary;
quit;

 

New Contributor
Posts: 2

Re: PROC SQL and PROC MEANS default rounding in output

Thank you for explaining that!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 238 views
  • 1 like
  • 2 in conversation