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

SAS Innovate 2025: Call for Content! Submit your proposals before Sept 25. Accepted presenters get amazing perks to attend the conference!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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