SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NKormanik
Barite | Level 11

Would someone please suggest the SAS procedure for arriving at the answer?

Two columns of data.

Day of Week would be the numbers 1 - 7, a categorical variable.

Response variable Accidents would be daily numbers, a continuous variable.

Number of rows in data set is greater than 1000.

Any guidance appreciated.

Nicholas Kormanik

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Or Proc SQL approach:

data have;

input week$ accident;

cards;

1 23

2 324

3 134

1 134

2 367

3 87

1 56

;

proc sql;

select * from

  (select week, mean(accident) as max

  from have

  group by week)

   having max=max(max);

  quit;

Haikuo

View solution in original post

5 REPLIES 5
Reeza
Super User

Two possible options

1. Proc FREQ -

proc freq data=have;

     table day_of_week/chisq;

weight count;

run;

But that won't tell you which one is higher.

2. An ANOVA based on the average number per day of week with contrast tests to isolate the one that is the highest.

NKormanik
Barite | Level 11

What would be the code for ANOVA?

Sounds right, that SAS would have to calculate the average number of accidents for each day (1-7), and assess whether there is a significant difference between the days.

SteveNZ
Obsidian | Level 7

*get mean accidents per day;

proc summary noprint nway n

    data = have ;

            class days ;

            var accidents ;

    output out = want (

                    drop = _type_ _freq_)

        mean(accidents) = mean_accidents ;

run ;

Then run a proc rank to get the highest if required.

Haikuo
Onyx | Level 15

Or Proc SQL approach:

data have;

input week$ accident;

cards;

1 23

2 324

3 134

1 134

2 367

3 87

1 56

;

proc sql;

select * from

  (select week, mean(accident) as max

  from have

  group by week)

   having max=max(max);

  quit;

Haikuo

Reeza
Super User

I've been thinking as a statistician too long...did you need to test if its significantly different as well, or just after the largest number?

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1328 views
  • 3 likes
  • 4 in conversation