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 | . | No | Yes | Total |
. | 6764 | 12 | 5 | 6781 |
No | 14 | 2560 | 8 | 2582 |
Yes | 4 | 2 | 1280 | 1286 |
Total | 6782 | 2574 | 1293 | 10649 |
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.
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.
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.