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

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? Smiley Happy

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;

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

WAYS!

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 summary data=have chartype;
  
class have:;
   ways 2;
  
output out=twoway;
   run;

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

WAYS!

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 summary data=have chartype;
  
class have:;
   ways 2;
  
output out=twoway;
   run;
KevinViel
Pyrite | Level 9

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

stat_sas
Ammonite | Level 13

proc tabulate data=have out=want(drop=_type_ _page_ _table_);

class HaveAge HaveGender HaveIncome;

table HaveAge HaveGender HaveIncome,HaveAge HaveGender HaveIncome;

run;

Reeza
Super User

Make sure to correct for multiple testing.

http://xkcd.com/882/

Ksharp
Super User

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

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1316 views
  • 8 likes
  • 6 in conversation