Hi SAS friends,
I have a much larger version of the following dataset and my task is to perform cross-frequency tables on every binary variable (e.g. Has_Income HasGender etc..). i'm looking to capture every combination but I consider HasGender*HasIncome the same as HasIncome*HasGender. Can you help me solve this one?
data Have;
input ID $2. HaveAge HaveGender HaveIncome;
cards;
1 0 0 0
2 1 1 1
3 0 1 0
4 1 1 0
5 1 1 1
6 1 1 0
7 1 0 1
8 1 0 0
9 1 0 1
run;
proc freq data = Have;
table HaveAge*HaveGender/out=want1;
table HaveAge*HaveIncome/out=want2;
table HaveGender*HaveIncome/out=want3;
run;
WAYS!
WAYS!
As as statistician, I might warn against this for some purposes. Programmatically, you could do the following:
data one ;
array have_ ( 5 ) ( 5 * 1 ) ;
run ;
proc sql ;
create table name as
select name
from sashelp.vcolumn
where libname = "WORK"
and memname = "ONE"
;
quit ;
data _null_ ;
length tables_list $ 5000 ;
do i = 1 to &sqlobs. ;
set name point = i ;
do j = i + 1 to &sqlobs. ;
want + 1 ;
set name ( rename = ( name = name2 ))
point = j
;
tables_list = catx ( " "
, tables_list
, cat( "table "
, strip( name )
, "*"
, strip( name2 )
, "/out=want"
, strip( put( want , 8. ))
, ";"
)
) ;
end ;
end ;
call symput( "tables_list" , tables_list ) ;
stop ;
run ;
proc freq data = one ;
&tables_list. ;
run ;
Not sure how the formating (indenting) looks...
Of course, the only reason to take this approach in light of data_null_'s solution would be to learn about the various tools and data available. The CLASS statement above could be replaced with:
class _all_ ;
in certain circumstances.
HTH,
Kevin
proc tabulate data=have out=want(drop=_type_ _page_ _table_);
class HaveAge HaveGender HaveIncome;
table HaveAge HaveGender HaveIncome,HaveAge HaveGender HaveIncome;
run;
Make sure to correct for multiple testing.
data Have;
input ID $2. HaveAge HaveGender HaveIncome;
call sortn(HaveGender, HaveIncome);
cards;
1 0 0 0
2 1 1 1
3 0 1 0
4 1 1 0
5 1 1 1
6 1 1 0
7 1 0 1
8 1 0 0
9 1 0 1
run;
proc freq;
................
Xia Keshan
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.