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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
chelsealutz
Fluorite | Level 6

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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