Reading data into SAS
- Manual data entry with
data
step
data example1;
input subject age sex $ totchol bmi cigpday cvd $;
datalines;
1 39 M 195 26.97 0 Yes
2 46 F 250 28.73 0 No
3 48 M 245 25.34 20 .
4 61 F 225 28.58 30 Yes
;
run;
infile
statement withdata
step (can read any delimited text file)
data subset1;
infile "E:\SAS_video_1_2\framingham_subset.csv" delimiter="," firstobs=2;
/* add a colon modifier before the data format. The colon prevents read errors and allows SAS to correctly handle missing leading zeros in one digit months and days */
input RANDID INTAKE : MMDDYY10. TOTCHOL AGE SEX $ SYSBP;
format INTAKE MMDDYY10.
run;
proc import
statement
/* read Excel file */
proc import out=subset2
datafile= "E:\SAS_video_1_2\framingham_subset.xlsx"
dbms=XLSX REPLACE;
/* grab data from the worksheet "subset" in the original Excel file*/
sheet="subset"
/* There's a header row in the Excel file and SAS should use it to assign the variable names */
getnames=Yes;
run;
/* read csv file */
proc import out=subset3
datafile= "E:\SAS_video_1_2\framingham_subset.csv"
dbms=CSV REPLACE;
getnames=Yes;
run;
- import wizard
/* generate proc import code for reading*/
SAS procedures for viewing data
- Summaries of properties of SAS data file
proc contents
/* order=varnum: requests variable number ordering instead of alphabetical ordering in proc contents */
proc contents data=example1 order=varnum;
run;
- View actual file
proc print
/* print data */
proc print data=example1 order=varnum;
run;
/* print subset of observations and variables */
proc print data=example1 order=varnum (obs=5);
/* don't need to add dollar sign here */
var subject sex cvd;
run;
How to do statistical tests in sas:
Wilcoxon Rank sum: https://www.stat.purdue.edu/~tqin/system101/method/method_wilcoxon_rank_sum_sas.htm
Kruskal Wallis:
https://www.stat.purdue.edu/~tqin/system101/method/method_kruskal_wallis_sas.htm
One-way ANOVA:
https://www.stat.purdue.edu/~tqin/system101/method/method_one_way_ANOVA_sas.htm
t-test:
https://www.stat.purdue.edu/~tqin/system101/method/method_two_t_sas.htm