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.

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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