Hi experts!
So, I have two datasets, a midline and an endline. They have identical variables (different observations though, obviously) and I want to be able to compare changes in frequencies, etc between the two without having to go line by line in my output tables from each respective data sets' proc freq. I have 4 districts I'm looking at, and all of my proc freqs are stratified by these districtss. So, for example, what if I want to know the differences between how many said x, y, or z in response to indicator 4, from each set? Is there a way to do this?
I found this macro: http://www2.sas.com/proceedings/sugi26/p097-26.pdf but to be honest I have no idea how to input the info related to my data sets. I also tried proc compare, but I have no idea what the output means. As I'm sure you can tell, I'm pretty limited in my SAS knowledge and have been having trouble with the more nuanced procedures/code.
ANY help at all would be greatly appreciated! Thank you!
Almost there. Just need to sort by the dist variable:
Data stacked;
Set data1 data2 indsname=source;
Dset=source;
Run;
proc sort data=stacked; by dist; run;
Proc freq data=stacked;
By dist;
Table tb*dset;
Run;
The INDSNAME option takes the name of the origin data set for each record and puts it into a category variable (DSET, eventually) so you can compare the two populations.
Make one dataset and then run your proc freqs with the source as a crosstab variable.
Data stacked;
Set data1 data2 indsname=source;
Dset=source;
Run;
Proc freq data=stacked;
By district;
Table varx * dset;
Run;
I'm afraid I got this error:
Proc freq data=stacked;
1425 By dist;
1426 Table tb*dset;
1427 Run;
NOTE: Writing HTML Body file: sashtml.htm
ERROR: Data set WORK.STACKED is not sorted in ascending sequence. The current BY group has
dist = Samfya and the next BY group has dist = Luwingu.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 343 observations read from the data set WORK.STACKED.
NOTE: PROCEDURE FREQ used (Total process time):
real time 1.29 seconds
cpu time 0.32 seconds
And this output:
Frequency Percent Row Pct Col Pct |
|
| ||||||||
|
| ||||||||
|
|
Which is obviously only half of what I want. I apologize for being so new, I just don't know what this code is doing exactly. I understand combining the two datasets, but what exactly is the indsname option, or "source?"
Data stacked;
Set data1 data2 indsname=source;
Dset=source;
Run;
Proc freq data=stacked;
By district;
Table tb*dset;
Run;
That is what I ran...
Almost there. Just need to sort by the dist variable:
Data stacked;
Set data1 data2 indsname=source;
Dset=source;
Run;
proc sort data=stacked; by dist; run;
Proc freq data=stacked;
By dist;
Table tb*dset;
Run;
The INDSNAME option takes the name of the origin data set for each record and puts it into a category variable (DSET, eventually) so you can compare the two populations.
Thank you for clarifying! And @Reeza, thank you for that first step!
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.