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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2501 views
  • 4 likes
  • 5 in conversation