The script begins by creating an internal dataset, 'practice1', via a DATA STEP and 'datalines'. This dataset contains soda (Coke/Pepsi) and pet (dog/cat) preferences, along with a weight for each combination. Then, it uses the PROC FREQ procedure with the CHISQ option to perform a chi-square test to determine if there is a statistically significant association between soda preference and pet preference. The 'weight weight;' option is used to apply the weights specified in the dataset. The 'expected' and 'nocol' options display the expected counts and suppress column percentages.
Data Analysis
Type : CREATION_INTERNE
Data is created directly within the script via a DATA STEP and the DATALINES statement. It includes soda and pet preferences, as well as a weighting variable.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates the SAS dataset 'practice1'. It defines three variables: 'soda' (character), 'animal' (character), and 'weight' (numeric). The data is directly integrated into the script via the DATALINES statement, simulating observations of soda and pet preferences with their respective weights.
Copied!
data practice1;
input soda $ animal $ weight;
datalines;
Coke Dog 78
Coke Cat 22
Pepsi Dog 36
Pepsi Cat 64
;
run;
1
DATA practice1;
2
INPUT soda $ animal $ weight;
3
DATALINES;
4
Coke Dog 78
5
Coke Cat 22
6
Pepsi Dog 36
7
Pepsi Cat 64
8
;
9
RUN;
2 Code Block
PROC FREQ
Explanation : This PROC FREQ procedure analyzes the distribution of pet preferences by soda preference using the 'practice1' dataset. The 'tables soda*animal' statement creates a contingency table crossing these two variables. The 'chisq' option requests the calculation of the chi-square test for association. 'expected' displays the expected counts under the assumption of independence, and 'nocol' suppresses column percentages. The 'weight weight;' statement instructs the procedure to use the 'weight' variable as the frequency variable for calculations.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Practice: Test for a Difference Between Proportions
This code is posted for your benefit; however, I highly recommend that you practice typing your own SAS programs as well. With the SAS programming language, as with all new languages, immersion seems to be the best way to learn.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.