SAS Procedures

Help using Base SAS procedures
BookmarkSubscribeRSS Feed
Nupur20
Calcite | Level 5

HI,

I have a question regarding formatting percentages. Aftre running proc freq on one of the columns in my dataset, I get percentages as 33.33333 or 66.666666.

I have to ultimately export my data to excel so I want the percentages to show up as 33% or 33.33% which ever can be formatted easily.

Is there a way to format percentages in sas code itself?

thanks a ton

6 REPLIES 6
art297
Opal | Level 21

You didn't indicate if you were doing one way frequencies or crosstabulations, or whether you were getting your output from ods or as the result of an output statement.

If you are doing crosstabulations and using ods output files, then you could do something like:

proc format;

  picture pctfmt (round) other='009.99%';

run;

proc template;

  define crosstabs Base.Freq.CrossTabFreqs;

    cellvalue frequency percent rowpercent colpercent;

    define frequency;

      format=8.;

      header='Count';

    end;

    define percent;

      format=pctfmt.;

      header='Overall %';

    end;

    define rowpercent;

      format=pctfmt.;

      header='Row %';

    end;

    define colpercent;

      format=pctfmt.;

      header='Col %';

    end;

  end;

run;

proc freq data=sashelp.class;

  tables sex*age;

run;

Nupur20
Calcite | Level 5

This looks good but too complex for me to understand. is there a way to do this is excel automatically after importing data?

Just a thought!

art297
Opal | Level 21

I would think that it would be more difficult trying to do it automatically in Excel.  Post the code you are running as there might be an easier solution.

The template code isn't difficult.  It is just assigning a specific format to the output.  Difficult to figure out on one's own but, fortunately, many examples can be found on the web.

Nupur20
Calcite | Level 5

Thanks for your time.

This the code that I am using:

proc freq data = temp noprint;

tables Q1/out=Q1;

run;

is there any formta thing that I can add in this code to formta the percentages? What would you suggest?

art297
Opal | Level 21

There might be an easier way that I simply can't think of at the moment, but you could always just add one datastep and apply the desired format.  e.g.:

proc format;

   picture pctfmt (round) other='009.99%';

run;

 

proc freq data = sashelp.class noprint;

  tables age/out=Q1 ;

run;

 

data q1;

  set q1;

  format percent pctfmt.;

run;

Peter_C
Rhodochrosite | Level 12

Nupur

there are interesting ways to have SAS direct Excel to format cells.

Many of these will be found in "ODS reporting". Here is a link to a relevant posting http://communities.sas.com/message/1820#1820

good luck

Peter       

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
  • 6 replies
  • 11686 views
  • 0 likes
  • 3 in conversation