BookmarkSubscribeRSS Feed
Sanjeevas
Calcite | Level 5

data a;
input party account$ balance;
datalines;
1 A1 50
1 A2 60
1 A3 30
2 A4 40
2 A5 50
3 A6 30
3 A7 90
run;

write a query to fetch all accounts listed to the party who has at least one account having balnce greater than 50?

6 REPLIES 6
Patrick
Opal | Level 21

Welcome to the SAS Communities!

Your question feels like homework/an exercise. What have you tried so far? Where do you get stuck?

Post the code you've already developed even if not fully working yet.

SASKiwi
PROC Star

A sub-query is a good way of doing this type of question:

proc sql;
  create table want as 
  select A.*
  from A as A
  inner join
  (select party
         ,count(*) as Accounts_Count
   from A
   where balance > 50
   group by party
  ) as B
 on A.party = B.party;
quit;
Sanjeevas
Calcite | Level 5
Thanks.!!
AndreaVianello
Obsidian | Level 7
 why  calculate  count(*) as Accounts_Count... ?

proc sql;
  create table want as 
  select A.*
  from A as A
  inner join
      (select distinct party  from A
       where balance > 50
      ) as B
 on A.party = B.party;
quit;
Ksharp
Super User
data a;
input party account$ balance;
datalines;
1 A1 50
1 A2 60
1 A3 30
2 A4 40
2 A5 50
3 A6 30
3 A7 90
;

proc sql;
create table want as
select * from a where party in
 (select party from a where balance>50) ;
quit;
AndreaVianello
Obsidian | Level 7
perfect !

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1523 views
  • 1 like
  • 5 in conversation