BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dustychair
Pyrite | Level 9

Hi all,

I have some questions on proc tabulate.

1. I want to get one decimal for percentages.

2. I want to put % sign after percentages.

3. EnglishLearnerEL variable is either Y or N. I want to display only when EnglishLearnerEL is Y. When I use where= EnglishLearnerEL="Y" it excludes EnglishLearnerEL =N and display only "Y" results. However, I want to show only EnglishLearnerEL =Y, not exclude them.

 

My code is below.

Thank you for your help

 

proc tabulate data=inc_sdf_alg_1 out=inc_sdf_alg_1_gender;
class  gender EnglishLearnerEL ;
table (gender EnglishLearnerEL)*(N*format=comma16. colpctn*f=percentn7.2) (all= 'Total'* format=comma16.),
 (all= 'Total'*format=comma16.);
 where EnglishLearnerEL="Y" ;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
dustychair
Pyrite | Level 9

Hi,

Thanks for suggestions. The first two statements resolved my first and second questions. Even though I could not resolve it this link is for the question 3.

 

134-2013: Tips for Generating Percentages Using the SAS® TABULATE Procedure

proc format;
picture pfmt (round) low-high='009.9%';
proc tabulate data=sdf.inc_sdf_&d._&j. out=inc_sdf_&j._&d._desc; class gender EnglishLearnerEL ; table Egender EnglishLearnerEL, (N*format=comma16.) (colpctn*f=pfmt.); run;

 

 

 

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

The WHERE statement filters the input, so PROC TABULATE never "sees" anything but the "Y" values, which then constitute 100%.

I suggest that you use PROC TABULATE with the OUT= option to create a dataset, and then print your report from that, filtering there without affecting the values.

For code suggestions, supply example data in a working data step with datalines, and show the expected result from that.

Astounding
PROC Star

Here's an approach you can use for a Y/N variable when  you want to print the percentage of Y values but not the percentage of N values.

 

In a DATA step, create a new variable that is 1 when the Y/N variable is Y, and 0 when it is N.

 

In PROC TABULATE, use that new variable in a VAR statement.  Tell PROC TABULATE to compute the mean of that new variable, and print the mean in the percent8.1 format.  Note that the mean of a 0/1 variable is the percentage of 1's.

dustychair
Pyrite | Level 9

Hi,

Thanks for suggestions. The first two statements resolved my first and second questions. Even though I could not resolve it this link is for the question 3.

 

134-2013: Tips for Generating Percentages Using the SAS® TABULATE Procedure

proc format;
picture pfmt (round) low-high='009.9%';
proc tabulate data=sdf.inc_sdf_&d._&j. out=inc_sdf_&j._&d._desc; class gender EnglishLearnerEL ; table Egender EnglishLearnerEL, (N*format=comma16.) (colpctn*f=pfmt.); run;

 

 

 

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!

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
  • 3 replies
  • 738 views
  • 2 likes
  • 3 in conversation