Sie sind auf Seite 1von 2

SAS (for Windows) Syntax

(reading an SAS Data file “*.sas7bdat”)

LIBNAME misc 'e:\';


DATA work.junedate;
SET misc.admitjune;
HtInFeet= Height / 12; WHERE Age between 25 and 55;
LABEL ID = 'Patient ID'
Name = 'Patient Name'
Sex = 'Gender'
Age = 'Patient Age'
Date = 'Date Seen'
Height = 'Height in Inches'
HtInFeet = 'Height in Feet'
Weight = 'Weight in Pounds'
ActLevel = 'Physical Activity'
Fee = 'Service Fee';

KEEP Name Sex Age Date HtInFeet Weight ActLevel Fee;

FORMAT Date MMDDYY10. Fee DOLLAR12.2;


Run;
Proc Print Data= work.junedate label;
Run;
Proc Means Data= work.junedate;
var Age HtInFeet Weight Fee;
Run;
Proc Freq Data= work.junedate;
tables Sex ActLevel;
Run;

Note* the example below has the LIBNAME path that you would use if you had loaded SAS onto your
personal PC. The path that you would use when referencing an sample data file from lab computers will be
different. On Lab Computers you will need to go to Windows Explorer to find the path that leads up to the
last two subdirectories of (“\ets\Sashelp”)

LIBNAME Productn 'c:\Program Files\SAS\SASFoundation\9.2\ets\Sashelp';


DATA labor;
SET Productn.Workers;
WHERE ELECTRIC between 300 and 350;
LABEL ELECTRIC = 'Electricans'
MASONRY = 'Bricklayers';
FORMAT Date MONYY5.;
Run;
Proc Print Data= work.labor label;
Run;
Proc Means Data= work.labor;
var MASONRY;
Run;

(Note: I am attaching the text file for this next example “sasclass.csv,” but I have removed the email listing
for one individual who listed their personal instead of their UIC email.)
(reading a .csv text file containing a header row)

DATA WORK.students;
Length NameL $ 16 NameF $ 11 NameM $ 8 Email $ 26 ;
INFILE 'E:\sasclass.csv' DLM = ',' MISSOVER DSD FIRSTOBS=2;
informat Date mmddyy10.;
format Date mmddyy10. ;
INPUT Date NameL $ NameF $ NameM $ Email $;
RUN;
PROC PRINT Data= work.students label;
RUN;

(Note: here is the language based to the Excel file you put on your flash drive)

(reading an MS Excel spreadsheet file )

LIBNAME Personel 'e:\Employees.xls';


DATA work.staffage;
SET Personel.'EMPSTUDY$'n;
AGEHIRED = (HDATE - BIRTHDAY)/365.5;
IF GENDER = 'M' THEN NUMSEX = 2;
ELSE NUMSEX = 1;
WHERE EDLEV BETWEEN 12 AND 20;
KEEP NAME_ DIVISION_ LOCATION_ GENDER EDLEV HDATE BIRTHDAY AGEHIRED
NUMSEX;
LABEL NAME_ = 'L F MI' DIVISION_ = 'Affiliation' LOCATION_ = 'City'
GENDER = 'Sex' EDLEV = 'Years of School' HDATE = 'Date of Hire';
FORMAT BIRTHDAY HDATE MMDDYY10.;
Run;

proc print data = work.staffage NOOBS label;


run;
proc freq data = work.staffage;
tables GENDER DIVISION_ LOCATION_;
Run;
proc means data = work.staffage;
var EDLEV;
Run;
proc corr data = work.staffage;
var NUMSEX EDLEV;
WITH AGEHIRED;
TITLE 'Correlations for Hiring Age';
TITLE2 'With Gender and Level of Education';
RUN;
GOPTIONS RESET= all;
PROC GCHART DATA= work.staffage;
VBAR GENDER;
WHERE LOCATION_ =: 'Cary';
TITLE 'Staff Ratio in Cary by Gender';
RUN;
Quit;

/* This is how to bracket text so that SAS reads it as an inert comment, rather than as a command */

Das könnte Ihnen auch gefallen