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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.