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?
compute n;
if name='Wilma' then call define('row','format','dollar10.');
else call define('row', 'format', 'percent10.1');
endcomp;
@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?
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;
How can I use this format conditionally? If a = 'wilma' then format 1?
compute n;
if name='Wilma' then call define('row','format','dollar10.');
else call define('row', 'format', 'percent10.1');
endcomp;
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
fred | stone | 6595700% | 15MAR2020 |
wilma | stone | 6579800% | 12FEB2020 |
aiming for
fred | stone | 6595700% | 15MAR2020 |
wilma | stone | $6579800 | 12FEB2020 |
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;
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;
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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.