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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.