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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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;
amit123_silwal
Calcite | Level 5
Thank you very much for your help. Really appreciated.
Arpit_Agarwal
Fluorite | Level 6

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.

amit123_silwal
Calcite | Level 5
Thanks for your help.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 786 views
  • 1 like
  • 3 in conversation