BookmarkSubscribeRSS Feed
mmohotsi
Obsidian | Level 7

I have a table of results and would like to format a column using two different formats. In the attached data set, the first four columns are constant whilst the last one is variable. The first record identified by Unit = "Std= Dev <" should be expressed as a number correct to two decimal places and the remaining records identified by Unit = "% >=" should be expressed as a percentage to two decimal places. The SAS programme I used is as follows:

 

proc format;
value _base_
0.16 = 0.16
other =[percent9.2];
value _target_
0.4 = 0.4
other =[percent9.0];
run;

proc report data= Dataset split ='*'
style (column) = [fontsize=6.8pt cellheight=0.8cm cellwidth=3.9cm]
style (header) = [fontsize=6.9pt backgroundcolor = lightblue fontweight = bold cellheight = 10.00mm]
style (report) = [fontsize=5.8pt ];
define Base / f=_base_.;
define Target / f= _target_.;
compute August2021;
If Units= 'Std Dev <=' then do; August2021 best4.;end; else do;August2021 percent10.2;end;
endcomp;
run;

 

4 REPLIES 4
ballardw
Super User

Short answer: you don't. Proc report doesn't allow mixed formats in a column per se.

 

I suggest that any process that relies on single values in formats for exceptions as you are attempting is flawed.

What will you do if the Base or target% value is ever the same as that Std dev?

 

I suspect you might be better off providing the data BEFORE your dataset example is built and then show what you expect the report to look like. For one consideration Proc Tabulate will allow creating statistics in ROWS and the results can be formatted differently in column because of it.

 

It also is not clear exactly what you want in the output as you have no Columns statement.

It might be easier to add a text version of the Aug2021 (or whatever) variable and just Print the desired variables.

Something like

data forreport;
   set dataset;
   length Augtext $ 10;
   If Units= 'Std Dev <=' then Augtext= put(August2021, best4.);
   else Augtext= put(August2021, percent10.2);
run;

In proc print provide a style override for each variable in a VAR statement if needed.

PhilC
Rhodochrosite | Level 12

I coded but I failed, and its getting close to quitting time.  I searched and I found examples like this:

 

from: SUGI 28: Using Formats and Other Techniques to Complete PROC REPORT Tables (sas.com)

proc report data=sugi28.virginia_pop nowd ; 
  column county pct_imputed population pop ;
   define county / group; 
   define population / analysis format=comma15. "Population"; 
   define pct_imputed/ format=percent9.3; 
   define Pop / computed “Population”; 
   compute pop /char length=23; 
      if percent_imputed.sum > .5 
         then pop = (right(put(population.sum, comma15.))|| ' !!' ) ;
         else pop = (right(put(population.sum, comma15.))||' ' ) ;
   endcomp; 
   rbreak after / summarize ol ; 
run;

Same here: SUGI 26: Format Challenges with PROC REPORT (sas.com)

 

I believe this can be done using PROC REPORT with conditionals inside compute blocks.  Maybe someone with better PROC REPORT experience can help?

 

I googled 'site:support.sas.com "PROC REPORT" change format'.

Cynthia_sas
SAS Super FREQ

Hi:
You need to use a CALL DEFINE with the 'format' argument to get mixed formats in a column in PROC REPORT. Here's an example:

Cynthia_sas_0-1630006773788.png

Usually, there is some condition which specifies the need for a different format. In this case, I arbitrarily used values for HEIGHT and WEIGHT. Note that I referred to HEIGHT in the CALL DEFINE by the simple variable name but since WEIGHT was defined as an ANALYSIS variable with a statistics of MEAN, in the IF statement I need to use the compound name WEIGHT.MEAN in my IF.

  Another common scenario for using a different format is to do something like show commas for most of the data cells representing currency and then using dollar signs or currency for the summary row, like this:

Cynthia_sas_1-1630007734465.png

Again, since the usage of SALES and RETURNS was SUM, the CALL DEFINE in the COMPUTE AFTER needed to use the compound name instead of _COL_ for the 1st argument to CALL DEFINE.

Cynthia

ChrisNZ
Tourmaline | Level 20

The approach you chose should work.

 

data DATA;
  A=1.5; UNIT='StdDev'; output;
  A=0.5; UNIT='PCT'   ; output;
run;

data _F;
  set DATA(rename=(A=START));
  retain FMTNAME 'report' HLO 'F';
  LABEL=ifc( UNIT='StdDev', '5.2', 'percent.2') ;
  output;
run; 

proc format cntlin=_F; run;

proc report data=DATA;
  columns A ;
  define A /display format=report.;
run;

 

A
1.50
50%

 

 

 

 

 

 

 

 

 

 

proc format ;
  value report 0-1=[percent.2] other =[5.2];
run;

data REPORT;
  A=0.5; output;
  A=1.5; output;
run;

proc report data=REPORT;
  columns A ;
  define A /display format=report.;
run;

A
50%
1.50

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 1794 views
  • 2 likes
  • 5 in conversation