BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
niharik
Calcite | Level 5

Hello Friends,

I have a variable X having values (.,Yes, No). I have this variable in two different datasets A and B with an ID. I have to find the frequency matrix of count of values in both datasets as below. Please help me how it is possible either with Proc freq or any other procedure.

 

X

datasetA

datasetB

Frequency
Percent
Row Pct
Col Pct

.

No

Yes

Total

.

6764
63.52
99.75
99.73

12
0.11
0.18
0.47

5
0.05
0.07
0.39

6781
63.68


No

14
0.13
0.54
0.21

2560
24.04
99.15
99.46

8
0.08
0.31
0.62

2582
24.25


Yes

4
0.04
0.31
0.06

2
0.02
0.16
0.08

1280
12.02
99.53
98.99

1286
12.08


Total

6782
63.69

2574
24.17

1293
12.14

10649
100.00

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

In order to get any analysis like this, you need the variables of interest in one data set; not separated in two data sets.

 

To combine the data sets, you would have to do a MERGE in a SAS data step, by ID, and also rename the variables so they both don't have the same name. Something like this

 

/* UNTESTED CODE */

data combined;
    merge a(rename=(x=x_a)) b(rename=(x=x_b));
    by id;
run;

 

For this to work, both data sets must be sorted by ID. Then PROC FREQ can take data set COMBINED and produce the report you want.

 

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

In order to get any analysis like this, you need the variables of interest in one data set; not separated in two data sets.

 

To combine the data sets, you would have to do a MERGE in a SAS data step, by ID, and also rename the variables so they both don't have the same name. Something like this

 

/* UNTESTED CODE */

data combined;
    merge a(rename=(x=x_a)) b(rename=(x=x_b));
    by id;
run;

 

For this to work, both data sets must be sorted by ID. Then PROC FREQ can take data set COMBINED and produce the report you want.

 

 

--
Paige Miller
niharik
Calcite | Level 5
Thank you. It worked after renaming, merging and running proc freq between renamed vars.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 592 views
  • 0 likes
  • 2 in conversation