I'm trying to only pick those primary keys with a code equal to A2391 AND A2392 ONLY - for each primarykey.
PrimaryKey Proc Code
a156273. A2391
a156273. A2392
c456373. A2391
c456373. A2392
c456373. A2393
b784734. A2391
b784734. A2392
Should look like this
a156273. A2391
a156273. A2392
b784734. A2391
b784734. A2392
c456373. A2391
c456373. A2392
So for each primary key, I want to bring in only those who have those codes.
This is one of those cases where it's easier if you reverse your logic
1. Find IDs that have something other than those two values.
2. Exclude those IDs
proc sql;
create table want as
select *
from have
where primaryKey not in
( select distinct PrimaryKey
from have
where proc_code not in ('A2391', 'A2392')
);
quit;
@anonymous_user wrote:
I'm trying to only pick those primary keys with a code equal to A2391 AND A2392 ONLY - for each primarykey.
PrimaryKey Proc Code
a156273. A2391
a156273. A2392
c456373. A2391
c456373. A2392
c456373. A2393
b784734. A2391
b784734. A2392
Should look like this
a156273. A2391
a156273. A2392
b784734. A2391
b784734. A2392
c456373. A2391
c456373. A2392
So for each primary key, I want to bring in only those who have those codes.
Thank you for your response.
I'm getting a syntax error - ERROR: 22-322: after where it says:
where PrimaryKey not in
log:
Proc Sql;
create table s.mergefinal as
select *
from s.merge
where PrimaryKey not in
ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER,
ERROR 76-322: Syntax error
(select distinct PrimaryKey from merge
where proc_code not in ('2391','2392')
);
quit;
NOTE: The SAS System stopped processing this step because of errors.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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: