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

Happy New Year everyone!

 

I would like to merge the results of 3 tables as a result of my proc freq data step.

How do I do this?

 

Example:

 

proc freq data = step;

tables (site_1 site_2 site_3)*gender / norow nocol nopercent nocum;

run;

 

where site_1, site_2 and site_3 has three possible options (A,B,C)

and gender = (M,F)

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You change the data set

 

data want;
    set have;
    site=site_1; output;
    site=site_2; output;
    site=site_3; output;
run;

and then you run your PROC FREQ on site*gender

--
Paige Miller

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

@yoyong555 wrote:


I would like to merge the results of 3 tables


This isn't particularly specific about what the "merge" should look like. Describe how such a "merge" should happen. Show us what the merged table should look like.

--
Paige Miller
yoyong555
Obsidian | Level 7

Hi Paige.

 

The table should look like this:

 

                            Site

Gender        A        B       C      Total

F                    

M

Total

PaigeMiller
Diamond | Level 26

How do we derive the numbers in the cells? What is the math? What is the formula?

--
Paige Miller
yoyong555
Obsidian | Level 7

I will have three tables as a result of my proc freq datasetp. The tables will look like:

 

                                 site_1

Gender           A          B        C      Total

F                     1         1         1         3

M                    2         2         0         4

Total               3         3          1        7

 

                                 site_2

Gender           A          B        C      Total

F                     3         4         6         13

M                    2         0         3           5

Total               5         4         9         18

 

                                 site_3

Gender           A          B        C      Total

F                     2         1         1         4

M                    4         2         5         11

Total               6         3          6        15

 

How do I merge the results of these tables to look like this:

 

                               site

Gender         A            B        C         Total

F                  6            6         8           20

M                 8            4         8           20

Total           14           10      16          40

 

Thank you.

PaigeMiller
Diamond | Level 26

You change the data set

 

data want;
    set have;
    site=site_1; output;
    site=site_2; output;
    site=site_3; output;
run;

and then you run your PROC FREQ on site*gender

--
Paige Miller
yoyong555
Obsidian | Level 7
Thank you.
Reeza
Super User
Use PROC TRANSPOSE to resturcture your input data, so that you have a single Site variable and then use PROC FREQ on the new data set.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 7 replies
  • 1655 views
  • 0 likes
  • 3 in conversation