BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
 compute n;
  if name='Wilma' then call define('row','format','dollar10.');
   else call define('row', 'format', 'percent10.1');
 endcomp;

View solution in original post

9 REPLIES 9
ballardw
Super User

@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?

Reeza
Super User

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;
DavidPhillips2
Rhodochrosite | Level 12

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

Reeza
Super User
 compute n;
  if name='Wilma' then call define('row','format','dollar10.');
   else call define('row', 'format', 'percent10.1');
 endcomp;
DavidPhillips2
Rhodochrosite | Level 12

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

 

BrunoMueller
SAS Super FREQ
you test for Wilma whereas your data is wilma
DavidPhillips2
Rhodochrosite | Level 12

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;

DavidPhillips2
Rhodochrosite | Level 12

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;

DavidPhillips2
Rhodochrosite | Level 12

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 9 replies
  • 1920 views
  • 4 likes
  • 4 in conversation