Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

proc freq or proc tabulate for cross-tab table 1

Status
Not open for further replies.

janelange

Technical User
Jun 12, 2003
45
0
0
US
Hello again,

I'm having some problems creating a cross-tabulated frequency table for variables (cesdg242 and mhspec2) with dichotomous values (0 or 1) and two class variables, (ethnic and random).

I've been trying to use proc tabulate, because although these values are easy to determine in proc freq, I haven't been able to figure out how to construct tables with the desired structure.

Using proc tabulate, I can't, however, figure out how to display all the information I need.

Here's the code of what I have so far:
Code:
proc tabulate data=month6.ypic06_reg missing;
class  ethnic random;
var cesdg242 mhspec2;
table ethnic*random,
cesdg242*(n mean nmiss) mhspec2*(n mean nmiss);
run;

However, rather than specifiy how many 0 and 1 responses there are for each variable in each category, I only have the mean and n. Of course the actual frequency of responses is readily determined from mean and n--the mean being the percent of obs with values of 1, but that's not how I'd like to display the data ideally.

Any thoughts are appreciated--
Jane
 
With the N and NMISS options, you can get the number of 0s and 1s by setting the variable to missing if it is 0...
 
Hi Chris,

thanks for the input. If I didn't have missing values that I wanted to tabulate as well, then your solution would be the ticket.

However, I have a work-around that uses sql that might be of interest to others, involving:

1.change missing value code to -1 in original file. (I was having trouble to get sql to count the missing responses otherwise).
2. use sql to count instances of 1, 0, -1 for the variables in each category, creating new variable called count_cesdg242
3. use proc tabulate to make cross tab table with cesdg242 as a class variable and the count variable in the var list.

Code:
*converts missing values to -1;
data ypic_06_reg_missing(drop=i);
set month6.ypic06_reg;
array testmiss(*) _numeric_;                                            
  do i = 1 to dim(testmiss);                                              
    if testmiss(i)=. then testmiss(i)=-1;                                    
  end;
run;

*make table for frequency of responses;
proc sql;
create table test as 
select random, ethnic, cesdg242, count(cesdg242) as count_cesdg242 from 
ypic_06_reg_missing
group by random, ethnic, cesdg242;

*create cross tab-table;
proc tabulate data=test;
class  ethnic random cesdg242;
var count_cesdg242;
table ethnic*random,
cesdg242*count_cesdg242;
run;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top