Solved
New Contributor
Posts: 3

# find out maximum day from dataset

Hi,

My name is Amit, I am new to SAS.I am using SAS9.3. I have a data set which contains data about crimes. I would like to find out on which day of the week the maximum crime occurred. For this I have tried the code below,

proc freq data=work.crime;
tables DayOfWeek;
run;

This code gives me the frequency for each day and I can decide from the frequency ,on which day the maximum crime occured. I would like to know if this is the correct way or not.If not, kindly help me in writing the required code.

Regards.

Amit B.

Accepted Solutions
Solution
‎05-29-2017 11:50 AM
Super User
Posts: 10,570

## Re: find out maximum day from dataset

This is a valid way to find what you wanted. Consider expanding your proc freq by writing to an output dataset, and sorting that by descending count

Another way would be SQL:

``````proc sql;
create table want as
select dayofweek, count(*) as number
from work.crime
group by dayofweek
order by number descending
;
quit;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

All Replies
Solution
‎05-29-2017 11:50 AM
Super User
Posts: 10,570

## Re: find out maximum day from dataset

This is a valid way to find what you wanted. Consider expanding your proc freq by writing to an output dataset, and sorting that by descending count

Another way would be SQL:

``````proc sql;
create table want as
select dayofweek, count(*) as number
from work.crime
group by dayofweek
order by number descending
;
quit;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
New Contributor
Posts: 3

## Re: find out maximum day from dataset

Thank you very much for your help. Really appreciated.
Occasional Contributor
Posts: 14

## Re: find out maximum day from dataset

[ Edited ]

There's another way you may use PROC FREQ to have highest frequency on top, rather than manually looking into the results to find one, not that using PROC SQL is wrong or anything.

Here's how -

proc freq data=work.crime order=freq;
tables DayOfWeek;
run;

ORDER=FREQ option would allow you see the results in descending order of frerquency.

Hope this helps.

New Contributor
Posts: 3