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.
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!
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.
Ready to level-up your skills? Choose your own adventure.