Help using Base SAS procedures

Proc Report Format Value via Compute

Accepted Solution Solved
Reply
Super Contributor
Posts: 497
Accepted Solution

Proc Report Format Value via Compute

Is there a way to use a  compute block in proc report to display a numeric column as an integer in one line and percent on another?


Accepted Solutions
Solution
‎06-29-2017 12:58 PM
Super User
Posts: 19,770

Re: Proc Report Format Value via Compute

Posted in reply to DavidPhillips2
 compute n;
  if name='Wilma' then call define('row','format','dollar10.');
   else call define('row', 'format', 'percent10.1');
 endcomp;

View solution in original post


All Replies
Super User
Posts: 11,343

Re: Proc Report Format Value via Compute

Posted in reply to DavidPhillips2

DavidPhillips2 wrote:

Is there a way to use a  compute block in proc report to display a numeric column as an integer in one line and percent on another?


Is this supposed to be conditional on another value? Row number? How do you know which display you want on a given line? or do you mean to display both for every result but on separate lines, possibly stacked in a cell?

Super User
Posts: 19,770

Re: Proc Report Format Value via Compute

Posted in reply to DavidPhillips2

You can alias a column and list it twice.

 

http://support.sas.com/kb/41/576.html

 

Modifying it slightly:

data example;
   input a $  b $ mydate mmddyy8.; ;
   datalines;
wilma stone   01122001
wilma stone   02122001
wilma stone   01012001
fred  stone   03052008
fred  stone   03152008
fred  stone   03152009
;
run;

ods html;

title 'MIN and MAX date per patient';

proc report nowd data=example;
   column a b mydate=min_mydate mydate=max_mydate;
   define a / group;
   define b / group;
   define min_mydate / min format=mmddyy10. 'min date';
   define max_mydate / max format=date9. 'max date';
run;

ods html close;
Super Contributor
Posts: 497

Re: Proc Report Format Value via Compute

How can I use this format conditionally?  If a = 'wilma' then format 1?

Solution
‎06-29-2017 12:58 PM
Super User
Posts: 19,770

Re: Proc Report Format Value via Compute

Posted in reply to DavidPhillips2
 compute n;
  if name='Wilma' then call define('row','format','dollar10.');
   else call define('row', 'format', 'percent10.1');
 endcomp;
Super Contributor
Posts: 497

Re: Proc Report Format Value via Compute

data example;
input a $ b $ mydate mmddyy8.;
datalines;
wilma stone 01122001
wilma stone 02122001
wilma stone 01012001
fred stone 03052008
fred stone 03152008
fred stone 03152009
;
run;

title 'MIN and MAX date per patient';

proc report nowd data=example;
column a b mydate=min_mydate mydate=max_mydate;
define a / group;
define b / group;
/*define min_mydate / min format=mmddyy10. 'min date';*/
define max_mydate / max format=date9. 'max date';
compute min_mydate;
if a='Wilma' then call define('min_mydate','format','dollar10.');
else call define('min_mydate', 'format', 'percent10.1');
endcomp;

run;

 

Results in 

a b mydate max date
fredstone6595700%15MAR2020
wilmastone6579800%12FEB2020

 

aiming for

 

a b mydate max date
fredstone6595700%15MAR2020
wilmastone$657980012FEB2020

 

SAS Super FREQ
Posts: 708

Re: Proc Report Format Value via Compute

Posted in reply to DavidPhillips2
you test for Wilma whereas your data is wilma
Super Contributor
Posts: 497

Re: Proc Report Format Value via Compute

Posted in reply to Bruno_SAS

Thanks

 

data example;
input a $ b $ mydate mmddyy8.;
datalines;
wilma stone 01122001
wilma stone 02122001
wilma stone 01012001
fred stone 03052008
fred stone 03152008
fred stone 03152009
;
run;

title 'MIN and MAX date per patient';

proc report nowd data=example;
column a b mydate=mydate2;
define a / group;
define b / group;
/*define min_mydate / min format=mmddyy10. 'min date';*/
/*define max_mydate / max format=date9. 'max date';*/
compute mydate2;
if a='wilma' then call define('mydate2','format','dollar10.');
else call define('mydate2', 'format', 'percent10.1');
endcomp;

run;

Super Contributor
Posts: 497

Re: Proc Report Format Value via Compute

[ Edited ]
Posted in reply to DavidPhillips2

I am trying to display the data across so I added a comma in

column a b mydate=mydate2;

Is there something I’m missing to display the data across?

 

The below works but

 

data example;
input a $ b $ mydate mmddyy8.;
datalines;
wilma stone 01122001
wilma stone 02122001
wilma stone 01012001
fred stone 03052008
fred stone 03152008
fred stone 03152009
;
run;

title 'MIN and MAX date per patient';

proc report nowd data=example;
column a b mydate=mydate2;
compute mydate2;
if a='wilma' then call define('mydate2', 'format','dollar10.');
endcomp;
define a / group;
define b / across;

run;

 

This block produces ERROR: Invalid column specification in CALL DEFINE.

 

data example;
input a $ b $ mydate mmddyy8.;
datalines;
wilma stone 01122001
wilma stone 02122001
wilma stone 01012001
fred stone 03052008
fred stone 03152008
fred stone 03152009
;
run;

title 'MIN and MAX date per patient';

proc report nowd data=example;
column a b, mydate=mydate2;
compute mydate2;
if a='wilma' then call define('mydate2', 'format','dollar10.');
endcomp;
define a / group;
define b / across;

run;

Super Contributor
Posts: 497

Re: Proc Report Format Value via Compute

Posted in reply to DavidPhillips2

This worked.

 

title 'MIN and MAX date per patient';

proc report nowd data=example;
column a b, mydate;
compute mydate;
if a='wilma' then call define(_col_, 'format','dollar10.');
endcomp;
define a / group;
define b / across;

run;

☑ This topic is solved.

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

Discussion stats
  • 9 replies
  • 291 views
  • 4 likes
  • 4 in conversation