DATA Step, Macro, Functions and more

find out maximum day from dataset

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

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: 6,982

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

View solution in original post


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

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
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

Re: find out maximum day from dataset

Thanks for your help.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 119 views
  • 1 like
  • 3 in conversation