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

Hi everyone,

I was wondering if anyone knows of a way to display the output from proc tabulate to the nearest 100, or a format that I could apply?  At the moment, I'm outputting to an excel spreadsheet and using the rounding function in excel, but it's pretty tedious.

Cheers,

Celia.

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

You can take advantage that with SAS9.4 we can create formats, that use functions to return the value.

here is an example:

*
* create a function to round
*;

proc fcmp outlib=work.func.sample;
  function xround100(value);
    return( round(value, 100) );
  endsub;
run;

*
* make function available
*;

options cmplib=work.func;

*
* create a format that uses the function
*;

proc format;
 
value xround100x
    low - high = [xround100()]
  ;
run;

*
* apply the format
*;

proc tabulate data=sashelp.cars;
  class origin type;
  var invoice;

 
table type, origin*invoice*f=xround100x.;
 
table type, origin*invoice;
run;

View solution in original post

5 REPLIES 5
BrunoMueller
SAS Super FREQ

You can take advantage that with SAS9.4 we can create formats, that use functions to return the value.

here is an example:

*
* create a function to round
*;

proc fcmp outlib=work.func.sample;
  function xround100(value);
    return( round(value, 100) );
  endsub;
run;

*
* make function available
*;

options cmplib=work.func;

*
* create a format that uses the function
*;

proc format;
 
value xround100x
    low - high = [xround100()]
  ;
run;

*
* apply the format
*;

proc tabulate data=sashelp.cars;
  class origin type;
  var invoice;

 
table type, origin*invoice*f=xround100x.;
 
table type, origin*invoice;
run;
Peter_C
Rhodochrosite | Level 12

Hi Celia

PROC FORMAT allows you to create your own format to do this.

The PICTURE statenent supports a multiplier which you could set as MULT= .01 to achieve that "divide by 100" and a ROUND option to complete the objective.

Something like:

proc format ;

picture hundth (round) 

       low-high = '0,000,009'(mult=.01) ;

run;

Use it in a tabulate table like

table ( rowclass all),( columnclass all)

       *analysisVar*sum=' '*f= HUNDTH. ;

good luck

peterC

Celia
Fluorite | Level 6

Thanks Peter.C,

This gives me the right results. eg. if the number was 722, the output gives me 7.  Is there a way to make the output 700 rather than 7?

Cheers,

Celia.

ChrisHemedinger
Community Manager

For those looking for more details about how to use a custom function in a SAS format definition, see:

Base SAS(R) 9.4 Procedures Guide, Third Edition

And also Rick Langston's paper from SAS Global Forum 2012:

Using the New Features in PROC FORMAT

Chris

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 7114 views
  • 1 like
  • 5 in conversation