Hi there,
I am new to proc report procedures, and I would like to ask a question regarding calculated value, and using calculated value to generate another calculated value.
For example, using the sample data below: (Fruit is spanned header)
/*
It is not right tool to calculate a variable,
try data step instead.
*/
data have;
input account : $20. apple pear peach;
id=1;
cards;
sales 100 200 400
cost 40 110 180
;
run;
options missing=' ';
proc report data=have nowd;
columns id account ('Fruit' apple pear peach);
define id/order noprint;
define account/display;
define apple/analysis sum;
define pear/analysis sum;
define peach/analysis sum;
compute peach;
if account='sales' then do;apple_s=apple.sum;pear_s=pear.sum;peach_s=peach.sum;end;
if account='cost' then do;apple_c=apple.sum;pear_c=pear.sum;peach_c=peach.sum;end;
endcomp;
compute after id;
account='profit';
apple.sum=apple_s-apple_c;
pear.sum=pear_s-pear_c;
peach.sum=peach_s-peach_c;
endcomp;
compute after;
account='profit% of pear';
apple.sum=.;
pear.sum=(pear_s-pear_c)/pear_s ;
peach.sum=.;
call define('pear.sum','format','percentn8.2');
endcomp;
break after id/summarize;
rbreak after/summarize;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.