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
Rhodochrosite | Level 12

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
Rhodochrosite | Level 12

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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 2 replies
  • 2703 views
  • 1 like
  • 2 in conversation