BookmarkSubscribeRSS Feed
Mil00
Fluorite | Level 6

I am trying to calculate total percent of each student horizontally (green arrow) using proc freq procedure, but the result I am getting is calculated vertically (orange arrow). Any help will be appreciated.

1example.PNG

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Is it a requirement to use PROC FREQ?

Mil00
Fluorite | Level 6

No, it's not. I just need to count them horizontally

PaigeMiller
Diamond | Level 26
data want;
    set have;
    count = sum(of weekno1-weekno12);
run;
--
Paige Miller
PaigeMiller
Diamond | Level 26

PROC FREQ, by itself will not produce the count you want. You can do this in either a DATA step, or PROC TRANSPOSE followed by PROC FREQ, or possibly other methods.

--
Paige Miller
ballardw
Super User

@Mil00 wrote:

I am trying to calculate total percent of each student horizontally (green arrow) using proc freq procedure, but the result I am getting is calculated vertically (orange arrow). Any help will be appreciated.

1example.PNG


If you need the Percent of values that are 1 on each row then the MEAN function is what you want:

You don't show valid SAS variable names for the week variables but

data want;
   set have;
   percent = mean(of week:);
run;

or explicitly list the variables of interest.

The mean will be between 0 and 1, so 0.5 = 50%. If you want to display percentage values then use a format like Percent8.2 , or do the multiply by 100 to shift the decimal.

 

Counting would be something different

 

n (of week: ) would give the number of variables that have a value. But you did not describe what you might actually be counting.