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

I have a dataset with character IDs (mix of numbers and letters) and I want to be able to know the count of the unique IDs when running crosstabs. I am using SAS version 9.4 Thank you in advance.

 

Here is an example of what I have: 

DATASET

OBS

ID

STATUS

1

A123

2

2

A123

2

3

A123

2

4

A123

2

5

3F55

1

6

3F55

1

7

D445

2

8

D445

2

9

D445

2

10

D445

2

11

D445

2

 

Current crosstab:

 

CURRENT TABLE

 

 

STATUS

 

ID

1

2

TOTAL

A123

0

4

4

3F55

2

0

2

D445

0

5

5

 

2

9

11

 

Wanted crosstab: 

 

WANT TO BE ABLE TO COUNT EVERY ID AS 1 (NOTE EVERY ID WILL FALL CONSISTENTLY INTO THE SAME STATUS)

 

 

 

 

WANTED TABLE

 

 

STATUS

 

ID

1

2

TOTAL

A123

0

1

1

3F55

1

0

1

D445

0

1

1

 

1

2

3

1 ACCEPTED SOLUTION
2 REPLIES 2
a_zacMD
Obsidian | Level 7

Thank you so much, it worked! 

 

While checking into it here is what I found, in case anyone out there needs it: 

There are 2 types of ways to remove duplicates. You can either remove duplicates where all variable values (nodup - EX1) are compared or remove duplicates for a single variable (nodupkey - EX2), for example by ID:

 

PROC SORT DATA=DATASET NODUP OUT=EX1;
BY ID;
RUN;
PROC FREQ DATA=EX1;
TABLES ID;
RUN;

PROC SORT DATA=DATASET NODUPKEY OUT=EX2;
BY ID;
RUN;
PROC FREQ DATA=EX2;
TABLES ID;
RUN;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2 replies
  • 881 views
  • 0 likes
  • 2 in conversation