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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.