SAS Procedures

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

I am trying to create a new column of batting average and round the column to three decimal places. This is the code I have been trying, but it is returning "0.3" for every value in the Batting Average column. 

 

 

PROC sql; 
SELECT name, team, round (nhits / natbat,0.3) as batavg label="Batting Average"
FROM sashelp.baseball
ORDER BY batavg desc;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisBrooks
Ammonite | Level 13

Hi @Steelersgirl  - I think your problem here is you're misunderstanding how the round function works. The second argument is the rounding unit and not the number of decimal places you want. You can see how this works if you look at the section titled "producing Expected Results" in. this link -> https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p0tj6cmga7p8qln1ejh6ebevm0c9.htm...

 

What you want is a rounding unit of 0.001 as in the code below

 

proc sql; 
 	SELECT name, team, round (nhits / natbat,0.001) as batavg label="Batting Average"
 	FROM sashelp.baseball
 	ORDER BY batavg desc;
quit;

View solution in original post

1 REPLY 1
ChrisBrooks
Ammonite | Level 13

Hi @Steelersgirl  - I think your problem here is you're misunderstanding how the round function works. The second argument is the rounding unit and not the number of decimal places you want. You can see how this works if you look at the section titled "producing Expected Results" in. this link -> https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=p0tj6cmga7p8qln1ejh6ebevm0c9.htm...

 

What you want is a rounding unit of 0.001 as in the code below

 

proc sql; 
 	SELECT name, team, round (nhits / natbat,0.001) as batavg label="Batting Average"
 	FROM sashelp.baseball
 	ORDER BY batavg desc;
quit;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 1 reply
  • 53116 views
  • 2 likes
  • 2 in conversation