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.
Is it a requirement to use PROC FREQ?
No, it's not. I just need to count them horizontally
data want;
set have;
count = sum(of weekno1-weekno12);
run;
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.
@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.
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.
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!
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.