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