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

Hi.....I have two variables - Client & Code. I would like to extract a list of Clients with their code where the code is either a 1 or 2 or 3 as well as the other codes for only these same clients. Can this done using a Proc SQL?...Thanks in Advance.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Yes, use an EXISTS clause:

proc sql;

create table want as

select *

from myTable as A

where exists (select * from myTable where client=A.client and code in (1, 2, 3));

quit;

(untested)

PG

PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

Yes, use an EXISTS clause:

proc sql;

create table want as

select *

from myTable as A

where exists (select * from myTable where client=A.client and code in (1, 2, 3));

quit;

(untested)

PG

PG
stat_sas
Ammonite | Level 13

data have;

input client code;

datalines;

1  1

1  2

2  1

2  2

2  3

3  1

3  2

3  4

3  5

4  8

4  1

;

data list;

input client;

datalines;

1

2

;

proc sql;

select * from have

where client in (select client from list);

quit;

twildone
Pyrite | Level 9

Thanks PG.....if I had 5 variables - Client, date_processed, code, eff_date, and ex_date and wanted to select the  row for the Client if the eff_dates and ex_dates are the same for the same client based on the maximum of date_processed to eliminate duplicates. Would a similar proc sql achieve this? Thanks in Advance.

PGStats
Opal | Level 21

Seems quite different. Please post as a new question, with a small example. - PG

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1071 views
  • 3 likes
  • 3 in conversation