Data have;
input id;
cards;
-1
-2
-3
10
20
30
;
run;
sum of nagative values in positive varible
sum of positive values in negative variable
like below
positive negative
60 -6
Data have;
input id;
if id<0 then negative+id;
else if id>0 then positive+id;
cards;
-1
-2
-3
10
20
30
;
run;
You have negative ID numbers?
Just for fun 🙂
Data have;
input id;
negative + (id<0)*id;
positive + (id>0)*id;
cards;
-1
-2
-2
10
20
30
;
run;
Bart
Just for fun.
Data have; input id; cards; -1 -2 -3 10 20 30 ; proc sql; select (select sum(id) from have where id>0) as positive, (select sum(id) from have where id<0) as negative from have(obs=1); 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.