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

I have a dataset like this (below). The variable code takes 4 possible values

The ID variable is not unique. There can be an ID with only code of the 4 possible, or with more than one code. I want to keep only the unique IDs. So if an ID is repeated I want to remove it. Objective is to keep all IDs that have only one code.

 

Obs       ID                         code

1       AE0000037163          C1
2       BN0000037282          U2
3       CD0000037693          U1
4       RS0000037738          U2
5       RS0000037738          C2

.                .                             .

.                .                             .

.                .                             .

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Use PROC SORT

 

proc sort data=have nouniquekey uniqueout=want;
    by id;
run;
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Use PROC SORT

 

proc sort data=have nouniquekey uniqueout=want;
    by id;
run;
--
Paige Miller
awesome_opossum
Obsidian | Level 7
proc sql; create table data1
as select distinct
*
from data;
quit; 

proc sql; create table data2
as select
*,
count(code) as k
from data1
group by id; 
quit; 

data data3; set data2; 
if k = 1; 
run; 
ChanceTGardener
SAS Employee
data have;
input obs id $ code $;
datalines;
1 AE0000037163 C1
2 BN0000037282 U2
3 CD0000037693 U1
4 RS0000037738 U2
5 RS0000037738 C2
;

proc sql;
create table want as 
select distinct id
from have
group by id
having count(code) eq 1;
quit;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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