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?
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;
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;
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!
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.