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

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;

Capture.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

I think you need to refer to these columns as _C1_ and _C2_

--
Paige Miller
SASKiwi
PROC Star

I suspect CatY may also count as a column so it could be _C2_ and _C3_.

PaigeMiller
Diamond | Level 26

Yep that's it @SASKiwi 

--
Paige Miller
Ksharp
Super User

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;
ed_sas_member
Meteorite | Level 14

 

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;

sas-innovate-wordmark-2025-midnight.png

Register Today!

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.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2714 views
  • 4 likes
  • 5 in conversation