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

I think I have a simple question however, I can not find the answer. My question is, I have to numeric variables that I am subtracting and I want the difference between those two variables without getting the negative sign. This is my code:

data diff;
input score score_1;
datalines;
2 7
6 8
5 3
5 9
;
run;

proc sql;
select*, (score-score_1) as score_diff
from diff;
quit;

The output is
score score_1 score_diff
2 7 -5
6 8 -2
5 3 2
5 9 -4

 

But I would like for the score_diff variable to be just 5,2,2,4. Could someone assist me with this please?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do this

 

data diff;
	input score score_1;
	datalines;  		
	2 7
	6 8
	5 3
	5 9
;      
run; 

proc sql; 
	select*, abs(score-score_1) as score_diff
	from diff; 
quit;  

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Do this

 

data diff;
	input score score_1;
	datalines;  		
	2 7
	6 8
	5 3
	5 9
;      
run; 

proc sql; 
	select*, abs(score-score_1) as score_diff
	from diff; 
quit;  
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
  • 1 reply
  • 619 views
  • 0 likes
  • 2 in conversation