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

Below is the data step I have which formats each number as a percent.  I want to round pct_in_school and pct_in_course  down to the nearest ten like so:

78% would be 70%

72% would be 70%

99% would be 90%

data rosters;

set allsets2;

diff = intck('WEEKDAY', entrydate, exitdate);

days_in_school = networkdays(entrydate, exitdate-1, "work.usholidays","holidaydate");

days_in_course = networkdays(dateenrolled, dateleft-1, "work.usholidays","holidaydate");

Pct_in_school=days_in_school/180;

Pct_in_course=days_in_course/180;

format Pct_in_school Pct_in_course percent12.;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Multiply by 10 to round to number such as 7.8, 7.2, 9.9. Apply the floor function and then convert back to percent by dividing by 10.

Simplifying the math it becomes:

Pct_in_school=floor(days_in_school/18)/10;

Pct_in_course=floor(days_in_course/18)/10;

format Pct_in_school Pct_in_course percent12.;

View solution in original post

2 REPLIES 2
Reeza
Super User

Multiply by 10 to round to number such as 7.8, 7.2, 9.9. Apply the floor function and then convert back to percent by dividing by 10.

Simplifying the math it becomes:

Pct_in_school=floor(days_in_school/18)/10;

Pct_in_course=floor(days_in_course/18)/10;

format Pct_in_school Pct_in_course percent12.;

ballardw
Super User

And just in case you might like to keep the original value but display use a custom format:

proc format ;

value MyPct

0   -< 0.1 = '  0%';

0.1 -< 0.2 = ' 10%'

0.2 -< 0.3 = ' 20%'

<repeat pattern>

0.9 -< 1  = ' 90%'

1            =  '100%'

;

run;

The spaces are so some procedures can display formatted values in an appropriate sorted appearance.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 800 views
  • 3 likes
  • 3 in conversation