BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Chris_LK_87
Quartz | Level 8

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Chris_LK_87
Quartz | Level 8

Thank you!

 

Your solution worked. 

 

Of course BALANCE should be numerical, my mistake. 

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
  • 2 replies
  • 412 views
  • 0 likes
  • 2 in conversation