Data originates from an external CSV file ('/home/gsturrock0/STAT1/RepIncome..csv') imported via PROC IMPORT. The script does not contain internal data (datalines/cards) nor does it use SASHELP data.
1 Code Block
PROC IMPORT Data
Explanation : This block initializes the environment and imports data. The %web_drop_table macro deletes an existing SAS table. FILENAME associates a logical name (REFFILE) with the external CSV file path. PROC IMPORT reads this CSV file and converts it into a SAS dataset named WORK.repincome, using the first row as variable names (GETNAMES=YES). PROC CONTENTS displays the imported dataset's metadata. Finally, %web_open_table is used to view the table in SAS Studio.
Explanation : This block is dedicated to exploratory data visualization. The two PROC SGPLOT calls create graphs: the first generates a box plot (vbox) of incomes ('income') for each candidate ('category=candidate'), and the second produces a scatter plot (scatter) of incomes ('y=income') as a function of the candidate ('x=candidate'). These graphs help understand the distribution and relationship between incomes and candidates.
Explanation : This block focuses on the comparison between 'Trump' and 'Carson'. A DATA step creates a new dataset 'TrumpCarson' by filtering 'work.repincome' to include only observations where the candidate's 'code' is not '3' (thus excluding the third candidate). Then, PROC NPAR1WAY performs a non-parametric Wilcoxon test on the 'income' variable, using 'candidate' as the classification variable, with a significance level (alpha) of 0.05. The exact Wilcoxon test is requested, with Hodges-Lehmann (HL) difference estimation. A specific title 'Trump Carson' is added to the output report.
Copied!
*Trump Carson comparison;
DATA TrumpCarson; SET work.repincome;
IF code NE 3;
RUN;
proc npar1way data=TrumpCarson wilcoxon alpha=.05;
var income;
class candidate;
exact wilcoxon HL;
title 'Trump Carson';
run;
title;
1
*Trump Carson comparison;
2
DATA TrumpCarson; SET work.repincome;
3
IF code NE 3;
4
RUN;
5
6
PROC NPAR1WAYDATA=TrumpCarson wilcoxon alpha=.05;
7
var income;
8
class candidate;
9
exact wilcoxon HL;
10
title 'Trump Carson';
11
RUN;
12
title;
4 Code Block
DATA STEP / PROC NPAR1WAY Data
Explanation : Similar to the previous block, this segment prepares and analyzes data for the 'Trump' versus 'Cruz' comparison. A DATA step filters 'work.repincome' to create 'TrumpCruz', excluding the candidate with 'code' '2'. PROC NPAR1WAY is then called to perform a Wilcoxon test on 'income' by 'candidate', with the same analysis parameters (alpha=0.05, exact Wilcoxon with HL). The report is titled 'Trump Cruz'.
Copied!
*Trump Cruz Comparison;
DATA TrumpCruz; SET work.repincome;
IF code NE 2;
RUN;
proc npar1way data=TrumpCruz wilcoxon alpha=.05;
var income;
class candidate;
exact wilcoxon HL;
title 'Trump Cruz';
run;
title;
1
*Trump Cruz Comparison;
2
DATA TrumpCruz; SET work.repincome;
3
IF code NE 2;
4
RUN;
5
6
PROC NPAR1WAYDATA=TrumpCruz wilcoxon alpha=.05;
7
var income;
8
class candidate;
9
exact wilcoxon HL;
10
title 'Trump Cruz';
11
RUN;
12
title;
5 Code Block
DATA STEP / PROC NPAR1WAY Data
Explanation : This final block performs the comparison between 'Cruz' and 'Carson'. A 'CruzCarson' dataset is created by filtering 'work.repincome' to exclude the candidate with 'code' '1'. Then, PROC NPAR1WAY is used for a Wilcoxon test on the incomes ('income') of the remaining candidates ('candidate'), applying the same specifications as the previous analyses (alpha=0.05, exact Wilcoxon with HL). The title 'Cruz Carson' is assigned to the analysis result.
Copied!
*Cruz Carson comparison;
DATA CruzCarson; SET work.repincome;
IF code NE 1;
RUN;
proc npar1way data=CruzCarson wilcoxon alpha=.05;
var income;
class candidate;
exact wilcoxon HL;
title 'Cruz Carson';
run;
title;
1
*Cruz Carson comparison;
2
DATA CruzCarson; SET work.repincome;
3
IF code NE 1;
4
RUN;
5
6
PROC NPAR1WAYDATA=CruzCarson wilcoxon alpha=.05;
7
var income;
8
class candidate;
9
exact wilcoxon HL;
10
title 'Cruz Carson';
11
RUN;
12
title;
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.
Related Documentation
Aucune documentation spécifique pour cette catégorie.
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.