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

Completely new to SAS Enterprise Guide. I am currently working on a table where I have "Offender" and "County" The offender can repeat but should only be counted as 1 even if it shows up 10 times. How can I count the occurance of county based on a unique Offender?

 

Offender          County

1                       Duval

1                       Duval

1                       Leon

2                       Hillsborough

4                       Duval

1                       Duval

5                       Clay

2                       Leon

 

This should result in:

 

Duval   2

Leon    2

Clay     1

Hillsborough   1

Manatee  1

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
proc sql;
create table want as
select  county,count(distinct offender) as count
from  have
group by county;
quit;

View solution in original post

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Remove the duplicates, then count

 

/* REMOVE DUPLICATES */
proc sort data=have nodupkey;
    by county offender;
run;
/* COUNT */
proc freq data=have;
     tables county;
run;
    
--
Paige Miller
FLCrime
Fluorite | Level 6

This seems pretty straight forward to me. I tried and got the attached error. Again I apologize I have no experience with this program or SQL. I've been using the point and click features and building queries that way.Error.PNG

PaigeMiller
Diamond | Level 26

You must use the name of your SAS data set. You cannot use the name of the SAS data set that I used as an example, HAVE.

--
Paige Miller
FLCrime
Fluorite | Level 6

That was my assumption. I tried my file name which is "pROGRESS" yes terrible capitalization I know. I tried the what I think is the table name "COUNTYT" and the same error comes back saying that it doesn't exist.

PaigeMiller
Diamond | Level 26

Replace HAVE with COUNTYT.

 

The tables command under PROC FREQ should use variable name COUNTY

--
Paige Miller
FLCrime
Fluorite | Level 6

ERROR2.PNG

Not sure what I did wrong here.

PaigeMiller
Diamond | Level 26

I guess you are going to have to find the proper name of your SAS data set, because COUNTYT is not right. Perhaps it is SOMETHING.COUNTYT, where SOMETHING is a library name.

--
Paige Miller
novinosrin
Tourmaline | Level 20

Hi @FLCrime  An alternative

 

data have;
input Offender          County :$15.;
cards;
1                       Duval
1                       Duval
1                       Leon
2                       Hillsborough
4                       Duval
1                       Duval
5                       Clay
2                       Leon
;



proc sql;
create table want as
select  county,count(*) as count
from (select distinct offender,county from have)
group by county;
quit;
Ksharp
Super User
proc sql;
create table want as
select  county,count(distinct offender) as count
from  have
group by county;
quit;
ballardw
Super User

Another is a double Proc Freq:

 

proc freq data=have noprint;
   tables offender*county /output out=temp;
run;
proc freq data=temp;
   tables county;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 10 replies
  • 1588 views
  • 5 likes
  • 5 in conversation