- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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