Hi Everyone,
Learning sas through example, and I'm reading this line of code but I'm not sure I uderstsand what is hapening.
proc tabulate data = ies_all2;
class site schedule location csr instructions comfort_wr comfort_er clinic_skill questions privacy experience;
classlev schedule location csr instructions comfort_wr comfort_er clinic_skill questions privacy experience / s=[just=right font_style=italic font_weight=light];
table schedule location csr instructions comfort_wr comfort_er clinic_skill questions privacy experience all, site * (n*f=3.0 colpctn="%"*f=4.1)/ misstext = "--";
format site site. schedule location csr instructions comfort_wr comfort_er clinic_skill questions privacy experience posf.;
run;
Specifcally I'm confused about what the following part of the above code is doing:
(n*f=3.0 colpctn="%"*f=4.1)/ misstext = "--"
Can someone please explain this to me?
Thank you!
Someone needs to learn how to format code for readability.
You need to look at a bit more code to answer the question:
site * (n*f=3.0 colpctn="%"*f=4.1)/ misstext = "--";
The n asks for a count of Site crossed with all values of the variables in the first line, the f=3.0 says to display the count with 3 digits, colpctn calculates the column percentage of the site count for each level of the first line variables, the ="%" says to display the percent sign as the column label and f=4.1 says to show the percentage with 4 characters and 1 value to the right of the decimal. The Misstext="--" says if there is no values for combinations of the row and column then display the characters -- instead of the default missing character.
Someone needs to learn how to format code for readability.
You need to look at a bit more code to answer the question:
site * (n*f=3.0 colpctn="%"*f=4.1)/ misstext = "--";
The n asks for a count of Site crossed with all values of the variables in the first line, the f=3.0 says to display the count with 3 digits, colpctn calculates the column percentage of the site count for each level of the first line variables, the ="%" says to display the percent sign as the column label and f=4.1 says to show the percentage with 4 characters and 1 value to the right of the decimal. The Misstext="--" says if there is no values for combinations of the row and column then display the characters -- instead of the default missing character.
thank you so much ballardw! that was such a clear and concise answer.
Sorry I don't know how to post code here I thought I was doing it correctly!
so "f" just means the value then?
Not a problem with posting the code but It is hard to read code that is so wide.
Consider:
proc tabulate data = ies_all2;
class site;
class schedule location csr instructions comfort_wr comfort_er
clinic_skill questions privacy experience;
classlev schedule location csr instructions comfort_wr comfort_er
clinic_skill questions privacy experience
/ s=[just=right font_style=italic font_weight=light];
table schedule location csr instructions comfort_wr comfort_er
clinic_skill questions privacy experience,
site * (n*f=3.0 colpctn="%"*f=4.1)
/ misstext = "--";
format site site. schedule location csr instructions comfort_wr comfort_er
clinic_skill questions privacy experience posf.;
run;
The two Class statements group the variables by "role" in the table. The ClassLev is easier to see what the actual style elements are without having to scroll out to the right in the code.
The Table statement has the Row and column separated so it is easier to see which role they play in the table and the table options are on a separate line. When you start writing Proc Tabulate code with many varaibles, statistics, style overrides and formats it can get pretty confusing what goes with which element. So visually aligning code elements (code formatting) will make the code easier to understand, maintain and modify.
I have some table statements in proc tabulated that run to 12 or 15 lines for one table and have multiple tables generated within a single tabulate call. Organizing the code saves a lot of headaches.
Ohh I've never seen code organized like that. It is way easier to read! I will try to incorporate that into my work
Thanks so much this was very valuable!
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.