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;  

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 357 views
  • 0 likes
  • 2 in conversation