- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;