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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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