Desktop productivity for business analysts and programmers

How to obtain different output style in same column of a summary table

Accepted Solution Solved
Reply
New User
Posts: 1
Accepted Solution

How to obtain different output style in same column of a summary table

Inside my project, I'd like to create a summary table in which I represent for each indicator the score relating to a specific date.

The problem is that the correct data type for almost all indicators is PERCENTN9.2 while for one is 6.

 

In other words, my output should be

 

Indicator      Score

1                    12,86%

2                    110,96%

3                    4.853

4                    30,64%

 

Is it possible to obtain this output?


Accepted Solutions
Solution
‎06-01-2017 05:30 AM
SAS Super FREQ
Posts: 706

Re: How to obtain different output style in same column of a summary table

Hi

 

If it is for printed output, you can use Proc REPORT and the CALL DEFINE routine to achive this, see example below.

 

data have;
  input
    Indicator
    Score
;
cards;
1 0.1286
2 1.1096
3 4.853
4 0.3064
;

proc report data=have;
  column indicator score _dummy;
  define indicator / display;
  define score / display;
  define _dummy / computed noprint;

  compute _dummy;
    if indicator = 3 then do;
      call define("score", "format", "8.4");
    end;
    else do;
      call define("score", "format", "percentn9.2");
    end;
  endcomp;
run;

View solution in original post


All Replies
Super User
Super User
Posts: 7,727

Re: How to obtain different output style in same column of a summary table

Yes. What youwould do is create a character variable (remember character variables can hold anything) and then put each of your values into the correct format into there and print that (score_char in the below will contain the mismatched formats):

data want (keep=indicator score_char);
  set have;
  length score_char $200;
  score_char=ifc(indicator=3,put(score,5.3),put(score,percent5.));
run;
Solution
‎06-01-2017 05:30 AM
SAS Super FREQ
Posts: 706

Re: How to obtain different output style in same column of a summary table

Hi

 

If it is for printed output, you can use Proc REPORT and the CALL DEFINE routine to achive this, see example below.

 

data have;
  input
    Indicator
    Score
;
cards;
1 0.1286
2 1.1096
3 4.853
4 0.3064
;

proc report data=have;
  column indicator score _dummy;
  define indicator / display;
  define score / display;
  define _dummy / computed noprint;

  compute _dummy;
    if indicator = 3 then do;
      call define("score", "format", "8.4");
    end;
    else do;
      call define("score", "format", "percentn9.2");
    end;
  endcomp;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 132 views
  • 0 likes
  • 3 in conversation