Hello,
I have a dataset with individuals that contains their balance. The individuals can appear multiple times. I would like to select the individuals that both have positive and negative balance.
data have;
length id $10 balance $48;
input id$ balance$;
datalines;
1 25
1 10
2 20
2 -30
3 40
3 80
4 -7
4 2
;
run;
Data want;
set have;
id$ balance$
2 20
2 -30
4 -7
4 2
Is there some reason you have BALANCE as a character variable?
data have;
input id $ balance;
datalines;
1 25
1 10
2 20
2 -30
3 40
3 80
4 -7
4 2
;
run;
proc sql;
create table want as select *
from have
group by id
having min(balance)<0 and max(balance)>0;
run;
Is there some reason you have BALANCE as a character variable?
data have;
input id $ balance;
datalines;
1 25
1 10
2 20
2 -30
3 40
3 80
4 -7
4 2
;
run;
proc sql;
create table want as select *
from have
group by id
having min(balance)<0 and max(balance)>0;
run;
Thank you!
Your solution worked.
Of course BALANCE should be numerical, my mistake.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: