DATA Step, Macro, Functions and more

Can someone please explain what this code is doing?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 88
Accepted Solution

Can someone please explain what this code is doing?

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!

 

 

 

 

 

 

 

 


Accepted Solutions
Solution
‎11-08-2016 11:47 AM
Super User
Posts: 10,500

Re: Can someone please explain what this code is doing?

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


All Replies
Solution
‎11-08-2016 11:47 AM
Super User
Posts: 10,500

Re: Can someone please explain what this code is doing?

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.

Frequent Contributor
Posts: 88

Re: Can someone please explain what this code is doing?

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?

Super User
Posts: 10,500

Re: Can someone please explain what this code is doing?

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.

Frequent Contributor
Posts: 88

Re: Can someone please explain what this code is doing?

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!

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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