Last active
August 13, 2017 20:58
-
-
Save idrissrasheed/93126da217a3a01c58f75f48fe2ca3dc to your computer and use it in GitHub Desktop.
SAS HW assignments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* exercise 1 */ | |
/* set library location */ | |
LIBNAME "C:\Users\SSMS1301-14\Desktop\PSTAT 130 M17" | |
/* reads airport data with three variables*/ | |
data work.airports; | |
infile 'airports.dat'; | |
input @ 1 Code $3. | |
@ 4 City $50. | |
@54 Country $15.; | |
run; | |
/* outputs the processed airport data */ | |
proc print data=work.airports; | |
run; | |
/* exercise 2 */ | |
/*reads data */ | |
DATA exercise2; | |
/* Build dataframe for variables */ | |
INPUT x y z; | |
/* Build dataframe for variables */ | |
CARDS; | |
17 129 43 | |
42 134 98 | |
26 185 54 | |
22 165 65 | |
; | |
RUN; | |
PROC PRINT data=exercise2; | |
RUN; | |
/* Exercise 3 */ | |
DATA exercise3; | |
/*Make x, y, and z variables*/ | |
INPUT x y z; | |
/* Build dataframe for variables */ | |
DATALINES; | |
17 129 43 | |
42 134 98 | |
26 185 54 | |
22 165 65 | |
; | |
RUN; | |
PROC PRINT data=exercise3; | |
RUN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1 */ | |
LIBNAME ia "C:\Users\SSMS1302-20\Desktop\PSTAT 130 M17\airlines one"; | |
PROC PRINT data = ia.personl; | |
PROC SORT data = ia.personl out=ia.personsl; | |
BY Gender LName; | |
RUN; | |
PROC PRINT dat = ia.personsl noobs; | |
BY Gender; | |
WHERE JobCode ? "FA" and State ="NY"; | |
VAR LName FName Gender Salary; | |
RUN; | |
/* 2 */ | |
PROC PRINT data=ia.personsl; | |
VAR LName FName; | |
WHERE LName ? "BR"; | |
RUN; | |
/* 3 */ | |
PROC PRINT data = ia.passngrs; | |
RUN; | |
PROC PRINT data = ia.passngrs; | |
OPTIONS nodate pageno = 1 ls = 64; | |
BY Dest; | |
RUN; | |
/* 3 */ | |
PROC PRINT data = ia.passngrs; | |
VAR Depart FClass BClass EClass; | |
SUM Depart FClass BClass EClass; | |
RUN; | |
PROC PRINT data = ia.passngrs; | |
TITLE "San Francisco Passenger Data"; | |
FORMAT Depart DATE9; | |
FORMAT FClass BClass EClass COMMA3.0; | |
RUN; | |
PROC PRINT data = ia.passngrs LABEL; | |
LABEL Dest = 'Destination' | |
Depart = 'Departure Date' | |
FClass = 'First Class' | |
BClass = 'Business Class' | |
EClass = 'Economy Class'; | |
RUN; | |
/* 4 and 5*/ | |
PROC PRINT data=ia.passngrs split=' ' noobs; | |
LABEL Dest='Destination' | |
Depart='Departure Date' | |
FClass='First Class' | |
BClass='Business Class' | |
EClass='Economy Class'; | |
VAR Dest Depart FClass BClass EClass; | |
SUM FClass BClass EClass; | |
TITLE1 'San Francisco Passenger Data'; | |
FORMAT depart DATE9.; | |
FORMAT FClass BClass EClass comma3.0; | |
FORMAT Dest $des.; | |
PROC FORMAT; | |
VALUE $Des 'ANC'='Anchorage' | |
'HNL'='Honolulu' | |
'SEA'='Seattle'; | |
RUN; | |
/* 6 */ | |
DATA ia.SF; | |
INFILE 'C:\Users\SSMS1302-20\Desktop\PSTAT 130 M17\airlines one\sfosch.dat'; | |
INPUT FlightID $ 1-7 | |
RouteID $ 8-14 | |
Destination $ 18-20 | |
Model $21-40 | |
DepartDay 51 | |
TotPassCap 65-67; | |
RUN; | |
PROC PRINT data = ia.SF; | |
RUN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Problem 1 */ | |
LIBNAME custfm 'C:\Users\SSMS1302-20\Desktop\custfm.xls'; | |
PROC CONTENTS data=custfm._all_; | |
RUN; | |
DATA work.males; | |
SET custfm.'Males$'n; | |
KEEP First_Name Last_Name Birth_Date; | |
FORMAT Birth_Date YEAR4.; | |
LABEL Birth_Date='Birth Year'; | |
RUN; | |
PROC PRINT data=work.males (firstobs = 1 obs=5); | |
RUN; | |
/* Problem 2*/ | |
LIBNAME prod 'C:\Users\SSMS1302-20\Desktop\products.xls'; | |
PROC CONTENTS data=prod._all_; | |
RUN; | |
DATA work.golf; | |
SET prod.'Sports$'n; | |
WHERE Category = 'Golf'; | |
Drop Category; | |
LABEL Name=Golf Products'; | |
RUN; | |
LIBNAME prod clear; | |
PROC PRINT data = work.golf (firstobs = 1 obs=10); | |
RUN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1 */ | |
LIBNAME ia 'C:\Users\SSMS1302-20\Desktop\PSTAT 130 M17\airlines one\'; | |
PROC PRINT data = ia.employees noobs N; | |
VAR EmpId | |
Country | |
Division | |
JobCode | |
Salary; | |
WHERE Country ? "CANADA"; | |
SUM Salary; | |
RUN; | |
/* 2 */ | |
PROC PRINT data = ia.passngrs; | |
RUN; | |
PROC SORT data = ia.passngrs out=ia.passngrss; | |
BY Dest; | |
RUN; | |
PROC PRINT data = ia.passngrss NOOBS; | |
BY Dest; | |
VAR Depart FClass BClass EClass; | |
RUN; | |
/* 3 */ | |
PROC PRINT data = ia.delay; | |
RUN; | |
PROC SORT data = ia.delay out=ia.delays NODUPKEY; | |
BY Dest descending Mail; | |
RUN; | |
PROC PRINT data = ia.delays NOOBS; | |
BY Dest; | |
VAR Flight Date Dest Mail; | |
SUM Mail; | |
RUN; | |
/* 4 */ | |
PROC PRINT data = ia.personl; | |
VAR LName FName; | |
WHERE LName ? "BR"; | |
RUN: | |
/* 5 */ | |
PROC SORT data = ia.passngrs out = passngrss; | |
BY Dest; | |
RUN; | |
PROC PRINT data = ia.passngrss; | |
OPTIONS nodate pageno = 1 ls = 64; | |
BY Dest; | |
VAR Depart FClass BClass ECLASS; | |
SUM Depart FClass BClass ECLASS; | |
TITLE1 'San Francisco Passenger Data'; | |
FORMAT depart DATE9.; | |
FORMAT FClass BClass EClass comma3.0; | |
LABEL Dest = 'Destination' | |
Depart = 'Departure Date' | |
FClass = 'First Class' | |
BClass = 'Business Class' | |
EClass = 'Economy Class'; | |
RUN; | |
/* 6 */ | |
PROC PRINT data = ia.fltat; | |
RUN; | |
PROC SORT data = ia.fltat, out = ia.fltatn; | |
BY HireDate; | |
RUN; | |
PROC PRINT data = ia.fltatn NOOBS; | |
OPTIONS nodate; | |
BY HireDate; | |
VAR HireDate EmpID Location JobCode Salary; | |
FORMAT HireDate YEAR4.; | |
RUN; | |
/* 9 */ | |
DATA sanfran; | |
PROC PRINT data = work.sanfran; | |
OPTIONS nodate nonumber ls = 72; | |
VAR FlightId | |
RouteID | |
Destination | |
Model | |
DepartDay | |
TotPassCap; | |
RUN; | |
PROC CONTENTS data = work.sanfran; | |
RUN; | |
/* 10 */ | |
LIBNAME ia 'C:\Users\SSMS1302-20\Desktop\SAS': | |
PROC PRINT data = ia.emplist; | |
RUN; | |
DATA ia.emplist; | |
INFILE 'emplist'; | |
INPUT LastName $ 1-20 | |
FirstName $ 21-30 | |
EmpId $ 31-36 | |
JobCode $36-43 | |
Salary 44-49; | |
BY EmpId; | |
RUN: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Excercise 5 */ | |
/* 1 */ | |
DATA work.sanfran; | |
INFILE 'C:\Users\SSMS1302-20\Desktop\sfosch.dat'; | |
INPUT @1 FlightID $7. @8 RouteID $7. | |
@18 Destination $3. @21 Model $20. | |
@41 Date date9. @65 TotPassCap 3.; | |
RUN; | |
PROC PRINT data=work.sanfran label; | |
FORMAT Date mmddyy10.; | |
LABEL FlightID='Flight ID' | |
RouteID='Route ID' | |
Model='Aircraft Model' | |
Date='Departure Date' | |
TotPassCap='Total Passenger Capacity'; | |
RUN; | |
PROC CONTENTS data=work.sanfran; | |
RUN; | |
/* 2 */ | |
PROC IMPORT DATAFILE = 'C:\Users\SSMS1302-20\Desktop\sfosch.csv' | |
OUT= WORK.sfocsv | |
DBMS=csv REPLACE; | |
getname=no; | |
RUN; | |
OPTIONS ls=72 nodate nonumber; | |
PROC PRINT data=work.sfocsv; | |
RUN; | |
/*3 */ | |
LIBNAME ia 'C:\Users\SSMS1302-20\Desktop\SAS'; | |
DATA raises; | |
SET ia.fltattnd; | |
KEEP EmpID Salary Increase NewSal; | |
IF JobCode='FLTAT1' THEN Increase=.10*Salary; | |
ELSE IF JobCode='FLTAT2' THEN Increase=.08*Salary; | |
ELSE IF JobCode='FLTAT3' THEN Increase=.06*Salary; | |
NewSal=sum(Salary,Increase); | |
RUN; | |
PROC PRINT data=raises; format Salary Increase NewSal dollar8.0; | |
RUN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1 */ | |
LIBNAME ia 'C:\Users\SSMS1302-20\Desktop\SAS'; | |
TITLE 'Employee Salary Data by Division / City'; | |
PROC REPORT data=ia.employees nowd; | |
COLUMN Division City Salary; | |
DEFINE Division / group width=20 'Division Name'; | |
DEFINE City / group width=13 'City Based'; | |
DEFINE Salary / format=dollar14.; | |
run; | |
/* Problem 2 */ | |
/* Each data set contains observations in the amounts shown below: | |
Ia.aprtarget 120 | |
Ia.maytarget 67 | |
Ia.juntarget 120 | |
The variable names in each data set are as follows: | |
Ia.aprtarget Flight, Destination, Date, FClassTar, EClassTar, FRev, ERev | |
Ia.maytarget FlightID, Destination, Date, FTarget, ETarget, FRev, ERev | |
Ia.juntarget FlightID, Destination, Date, FTarget, ETarget, FRev, ERev */ | |
/* Problem 3 */ | |
PROC GPLOT data=ia.delay; | |
WHERE Dest='CPH'; | |
PLOT Delay*Date / vaxis = -15 to 30 by 15; | |
TITLE c=red 'Flights to Copenhagen'; | |
SYMBOL i=needle c=red v=square; | |
RUN; | |
QUIT; | |
ods html close; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 1 */ | |
LIBNAME ia 'C:\Users\SSMS1302-20\Desktop\SAS'; | |
DATA usarea; | |
SET ia.states; | |
TotArea+Size; | |
NumStates+1; | |
RUN; | |
PROC PRINT data=usarea; | |
RUN; | |
/* 2 */ | |
data _null_; | |
SET ia.visits end=IsLast; | |
FILE 'visits.dat' dlm=','; | |
IF _N_ eq 1 THEN | |
put 'ID,Date,Fee'; | |
PUT ID | |
Date : mmddyy10. | |
Fee; | |
IF IsLast=1 then | |
PUT 'Data: PROG2.VISITS'; | |
RUN; | |
PROC FSLIST fileref='visits.dat'; | |
RUN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LIBNAME ia 'C:\Users\SSMS1302-20\Desktop\SAS'; | |
DATA separate(drop=FMnames); | |
LENGTH FMnames First MI Last $ 30; | |
SET ia.people; | |
First=scan(FMnames,1,' '); | |
MI=left(scan(FMnames,2,' ')); | |
Last=left(scan(Name,1,',')); | |
RUN; | |
PROC PRINT data=separate; | |
VAR Name CityState First MI Last; | |
RUN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATA work.salaries; | |
LENGTH ID $ 6 FName $ 8 LName $ 8 SalYear 4 Salary 5; | |
INFILE 'C:\Users\SSMS1302-20\Desktop\SAS\salaries.dat'; | |
INPUT Type $ @; | |
IF Type='E' THEN | |
INPUT ID $ FName $ LName $; | |
ELSE DO; | |
INPUT SalYear Salary; | |
OUTPUT; | |
END; | |
RUN; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment