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