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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.