Applying different numeric formats in proc report

Reply
Frequent Contributor
Posts: 87

Applying different numeric formats in proc report

i have data set

sno  Describtion Result

1      Maths       56

2     english      86

3     percent        67

4      total           89

5     percent_to   78

;

run;

i want output using proc report  as

sno  Describtion Result

1      Maths        56

2     english        86

3     percent        67.00%

4      total            89

5     percent_to    78.00%

;

run;

Super User
Super User
Posts: 7,942

Re: Applying different numeric formats in proc report

Hi,

You can pre-process the data to have a character variable with the result and manipulate it there:

data have;

attrib sno format=best. Description format=$200. Result format=best.;

infile datalines;

input sno description $ result;

datalines;

1      Maths       56

2     english      86

3     percent        67

4      total           89

5     percent_to   78

;

run;

data want (drop=result);

  set have;

  attrib resultc format=$200.;

  if sno in (3,5) then resultc=strip(put(result,5.2)||"%");

  else resultc=strip(put(result,best.));

run;

It may also be possible in proc report, though I would imagine you would need to write some compute blocks to handle each case and format from there.

Super User
Posts: 10,018

Re: Applying different numeric formats in proc report

use call define ().

data have;
input sno  Describtion : $20. Result ;
cards;
1      Maths       56
2     english      86
3     percent        67
4      total           89
5     percent_to   78
;
run;
proc format;
picture fmt
 low-high='09.99%';
run;
proc report data=have nowd;
columns sno  Describtion  Result;
compute result;
if describtion=:'percent' then call define(_col_,'format','fmt8.');
endcomp;
run;

Ksharp

Ask a Question
Discussion stats
  • 2 replies
  • 160 views
  • 1 like
  • 3 in conversation