BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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!

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

christinagting0
Quartz | Level 8

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?

ballardw
Super User

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.

christinagting0
Quartz | Level 8

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!

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 977 views
  • 2 likes
  • 2 in conversation