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.

 

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 782 views
  • 3 likes
  • 4 in conversation