BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
chelsealutz
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

 

chelsealutz
Fluorite | Level 6

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:

The FREQ Procedure

 

 

Frequency Percent Row Pct Col Pct
Table of tb by Dset tb Dset data1 Total 1 2 Total
124
72.94
100.00
72.94
124
72.94
 
 
46
27.06
100.00
27.06
46
27.06
 
 
170
100.00
170
100.00

 

 

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... 

 

ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
chelsealutz
Fluorite | Level 6

Thank you for clarifying! And @Reeza, thank you for that first step!

SAS Innovate 2025: Register Now

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!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2908 views
  • 1 like
  • 3 in conversation