BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello, My doubt is the follow. I have one question (variable) that has three option.
I´d like to calculate the percentage of firms by region that mark option "1".
This I can do, but I dind´t get that the other two option are exclude of output.
The example below illustrate the case.

Instead of
REGIONS (RG)-----------------Q176----------------ALL
--------------------------------1----------2------------3
--------------------------------%---------%----------%-----N
SUDESTE---------------50.0-------50.0-------0.0----2
NORDESTE-----------100.0--------0.0-------0.0----1
CENTRO-OESTE-------0.0--------0.0----100.0----1
SUL-----------------------100.0-------0.0--------0.0----1
ALL--------------------------60.0-----20.0------20.0----5

I would like
REGIONS (RG)------Q176----------ALL
--------------------------------1----------
--------------------------------%------------N
SUDESTE---------------50.0-----------2
NORDESTE-----------100.0-----------1
CENTRO-OESTE-------0.0-----------1
SUL-----------------------100.0-----------1
ALL--------------------------60.0----------5

Sincerely

Edmundo
4 REPLIES 4
deleted_user
Not applicable
tabulate will do this if you have a little pre-processing which generates a variable =1 where the answer chosen was 1(else =0). Perhaps [pre]
data prepare/view=prepare ;
set answers ; * your original data set of answers ;
q176_1 = (q176=1) ;
q176_2 = (q176=2) ;
q176_3 = (q176=3) ;
run;
proc tabulate data= prepare ;
var q176_1 ;
class region ;
table ( region all), q176_1='Q176' * pctsum='1' * f=5.2
n='all'*f=7.
/ rts= 20 ;
run;
deleted_user
Not applicable
Thank you Peter, but I still have one problem with the percentage row column and total column.
These two columns was not calculate in a proper way. Look example below.

Right table

Region--------------------------------------(Q174)
-------------------------------------1---------------------2------------------------Total
------------------------n------%C------%L-----n-----%C------%L-------n------%C-----%L
Sudeste------------1------33,3----33.3-----2-----100,0----66.7----3------60,0---100.0
Centro-oeste-----1------33,3---100.0------.---------.---------.-------1------20,0---100.0
Sul-------------------1------33,3---100.0------.---------.---------. ------1------20,0---100.0
Total----------------3-----100,0-----60.0-----2----100,0----40.0-----5----100,0---100.0

I´d like to exclude the option 2, but remain the percentage calculus over all 5 observations.

Region------------------------(Q174)
-------------------------------------1-------------------Total
------------------------n--------%C------%L-------n-----% C----%L
Sudeste-------------1-------33,3-----33.3------3-----60,0---100.0
Centro-oeste-------1------33,3----100.0------1-----20,0---100.0
Sul--------------------1-------33,3----100.0------1-----20,0---100.0
Total-----------------3------100,0-----60.0------5----100,0---100.0


Sincerely

Edmundo
deleted_user
Not applicable
sorry, out of practise - I forgot the important feature to mention and demo :
A percentage can be derived as [pre]
sum( of analysis varA )
100 * ---------------------------
sum( of analysis varB )[/pre] with small change like: [pre]
data prepare/view=prepare ;
set answers ;
* your original data set of answers ;
q176_1 = (q176=1) ;
q176_2 = (q176=2) ;
q176_3 = (q176=3) ;
retain one 1 ;
run;
proc tabulate data= prepare ;
var q176_1 one;
class region ;
table ( region all), q176_1='Q176'
* pctsum='1' * f=5.2
n='all'*f=7.
/ rts= 20 ;
run;
[/pre] try that approach....
At the back of my mind I feel the introduction of the "one" variable should be unneccessary, perhaps using pctn.
However, the important addition here is that using an analysis variable as percentage denominator definition, gives you a ratio of two analysis variables instead of the summary of each value of the class variable.

Good Luck

Peter-c
deleted_user
Not applicable
Many thanks Peter, you did it. Your approach work well.

You have a deep knowledge about SAS indeed.

sincerely

Edmundo

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
  • 709 views
  • 0 likes
  • 1 in conversation