Help using Base SAS procedures

re: Selecting Rows

Accepted Solution Solved
Reply
Regular Contributor
Posts: 229
Accepted Solution

re: Selecting Rows

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.


Accepted Solutions
Solution
‎10-07-2014 02:44 PM
Respected Advisor
Posts: 4,925

Re: re: Selecting Rows

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


All Replies
Solution
‎10-07-2014 02:44 PM
Respected Advisor
Posts: 4,925

Re: re: Selecting Rows

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
Trusted Advisor
Posts: 1,228

Re: re: Selecting Rows

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;

Regular Contributor
Posts: 229

Re: re: Selecting Rows

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.

Respected Advisor
Posts: 4,925

Re: re: Selecting Rows

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

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 228 views
  • 3 likes
  • 3 in conversation