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

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?

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenKuhfeld
Ammonite | Level 13

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

2 REPLIES 2
WarrenKuhfeld
Ammonite | Level 13

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;

 

spileggi
Calcite | Level 5

Thank you for explaining that!

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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