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.
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;
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;
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.
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!
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.