Hi all,
Using Proc Report I am trying to calculate the difference between the values of two cells under an across variable. Even after reading through some of the discussions and whitepapers I still can't get this to work.
Using below sample data the desired result in the first row under column diff_X1X2 is 1 ( 3-2) and -0.666.. in the 2nd row.
I do know that the value in categorical variable catX is either 'X1' or 'X2'
data have;
infile datalines truncover dlm=',' dsd;
input catX $ catY $ value;
datalines;
X1,Y1,2
X1,Y1,4
X1,Y2,1
X1,Y2,3
X2,Y1,2
X2,Y2,2
X2,Y2,3
X2,Y2,3
;
proc report data=have nowd;
column catY (catX, value diff_X1X2;
define catY / group ;
define catX / group across;
define value / analysis mean;
define diff_X1X2 / computed;
compute diff_X1X2;
diff_X1X2=_c_1-_c_2;
endcomp;
run;
As SASKiWI said ,it _c2_ and _c3_ , you could check its real name by option OUT= .
data have;
infile datalines truncover dlm=',' dsd;
input catX $ catY $ value;
datalines;
X1,Y1,2
X1,Y1,4
X1,Y2,1
X1,Y2,3
X2,Y1,2
X2,Y2,2
X2,Y2,3
X2,Y2,3
;
proc report data=have nowd out=temp;
column catY (catX, value diff_X1X2);
define catY / group ;
define catX / group across;
define value / analysis mean;
define diff_X1X2 / computed;
compute diff_X1X2;
diff_X1X2=_c2_-_c3_;
endcomp;
run;
I think you need to refer to these columns as _C1_ and _C2_
I suspect CatY may also count as a column so it could be _C2_ and _C3_.
Yep that's it @SASKiwi
As SASKiWI said ,it _c2_ and _c3_ , you could check its real name by option OUT= .
data have;
infile datalines truncover dlm=',' dsd;
input catX $ catY $ value;
datalines;
X1,Y1,2
X1,Y1,4
X1,Y2,1
X1,Y2,3
X2,Y1,2
X2,Y2,2
X2,Y2,3
X2,Y2,3
;
proc report data=have nowd out=temp;
column catY (catX, value diff_X1X2);
define catY / group ;
define catX / group across;
define value / analysis mean;
define diff_X1X2 / computed;
compute diff_X1X2;
diff_X1X2=_c2_-_c3_;
endcomp;
run;
proc report data=have nowd;
column catY (catX, value diff_X1X2);
define catY / group ;
define catX / across;
define value / analysis mean;
define diff_X1X2 / computed;
compute diff_X1X2;
diff_X1X2=_c2_-_c3_;
endcomp;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.