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

Accepted Solutions
ballardw
Super User

@superman1 wrote:

How does proc tabulate work exactly? I am being asked to Use proc tabulate to summarize variables age, test, gender, and  score where 75+ is pass vs. less than 85 is fail?


Since "75+" is "less than 85 for 75 to 84.99999 is have to assume you typed "85" where you meant "75".

Displaying text for range is often a Format that can be used by Proc Tabulate, Report, Print or other procedures.

 

Example data and expected result.

 

With proc tabulate grouping variables or those you want to count or get percentages of levels from some count the variables are placed on a CLASS statement. Variables that you want numeric statistic such as mean, min , max, standard deviation etc. are placed on a var statement. 

Here is brief example with just one way to consider summarizing sex, age and "group" created by a format for a continuous variable weight using a data set you should have available to run code.

Proc format;
value highweight
0-100= "Low"
100<-high = "High"
;

proc tabulate data=sashelp.class;
   class sex age weight;
   format weight highweight.;
   tables sex age weight,
          n='Count' pctn='%'
   ;
run;

Commas between things are used to create dimensions above the bit before the first comma would be a Row, then in the Columns (after the comma) we get counts and percentages.

If I wanted to get nested counts I would place an * between variables  sex*age would have the levels of age within sex.

One of the very nice things about Proc Tabulate is that you can request multiple tables such as:

proc tabulate data=sashelp.class;
   class sex age weight;
   format weight highweight.;
   tables sex age weight,
          n='Count' pctn='%'
   ;
   tables sex age  sex*age,
          weight *(n='Count' pctn='%')
   ;
   tables sex,
          Age*weight *(n='Count' pctn='%')
   ;
run;

One of the "bad" things is that you basically count combine statistics: you can't get the "mean" of a "max" in another column.

Note that there are multiple Pct options PctN is for counts, along with ColPctn, RowPctn, PagePctn,Reppctn and PctSum versions for use on VAR variables. There are many options for appearance, order of values and such. So you will want to bookmark the documentation.

View solution in original post

5 REPLIES 5
Shmuel
Garnet | Level 18

What do you mean by "where 75+ is pass vs. less than 85 is fail?"

What code did you used? Post the code and the log and point at what failed.

andreas_lds
Jade | Level 19

Sorry, but you need to improve your problem-description by posting example data in usable form (a data step using datalines).

ballardw
Super User

@superman1 wrote:

How does proc tabulate work exactly? I am being asked to Use proc tabulate to summarize variables age, test, gender, and  score where 75+ is pass vs. less than 85 is fail?


Since "75+" is "less than 85 for 75 to 84.99999 is have to assume you typed "85" where you meant "75".

Displaying text for range is often a Format that can be used by Proc Tabulate, Report, Print or other procedures.

 

Example data and expected result.

 

With proc tabulate grouping variables or those you want to count or get percentages of levels from some count the variables are placed on a CLASS statement. Variables that you want numeric statistic such as mean, min , max, standard deviation etc. are placed on a var statement. 

Here is brief example with just one way to consider summarizing sex, age and "group" created by a format for a continuous variable weight using a data set you should have available to run code.

Proc format;
value highweight
0-100= "Low"
100<-high = "High"
;

proc tabulate data=sashelp.class;
   class sex age weight;
   format weight highweight.;
   tables sex age weight,
          n='Count' pctn='%'
   ;
run;

Commas between things are used to create dimensions above the bit before the first comma would be a Row, then in the Columns (after the comma) we get counts and percentages.

If I wanted to get nested counts I would place an * between variables  sex*age would have the levels of age within sex.

One of the very nice things about Proc Tabulate is that you can request multiple tables such as:

proc tabulate data=sashelp.class;
   class sex age weight;
   format weight highweight.;
   tables sex age weight,
          n='Count' pctn='%'
   ;
   tables sex age  sex*age,
          weight *(n='Count' pctn='%')
   ;
   tables sex,
          Age*weight *(n='Count' pctn='%')
   ;
run;

One of the "bad" things is that you basically count combine statistics: you can't get the "mean" of a "max" in another column.

Note that there are multiple Pct options PctN is for counts, along with ColPctn, RowPctn, PagePctn,Reppctn and PctSum versions for use on VAR variables. There are many options for appearance, order of values and such. So you will want to bookmark the documentation.

superman1
Fluorite | Level 6
Thank you so much. this is a GREAT explanation instead of some of the explanations I have been reading online. Thank you again!
ballardw
Super User

@superman1 wrote:
Thank you so much. this is a GREAT explanation instead of some of the explanations I have been reading online. Thank you again!

There is a reason there is a publication "Proc Tabulate by Example" and in its second edition.

 

Really worth getting a copy if you want to 1) save time 2) reduce headaches 3) impress people with interesting tables.

 

Proc Report does the things that Tabulate doesn't, computes stuff using the results. So worth using as well.

Tabulate has advantages when you are nesting in multiple dimensions row and column that can get pretty nasty with Proc Report but again have to watch attempting to intersect statistics.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 639 views
  • 0 likes
  • 4 in conversation