Sei sulla pagina 1di 4

Titanic case study business questions and their associated SAS codes

/* Importing File*/ proc import datafile="C:\t3\titanic case\Titanic_Training_Raw.csv" out= rupinder.titanic dbms=csv; run; /* 1 How many passengers survived? */ proc freq data=rupinder.titanic; tables survived /nocum nopercent; where survived =1; run; /* 2 How many passengers didn't survive?*/ proc freq data=rupinder.titanic; tables survived /nocum nopercent; where survived =0; run; /* 3 How many female passengers survived?*/ proc freq data=rupinder.titanic; tables sex /nocum nopercent; where survived=1 and sex = "female"; run; /* 4 How many male passengers survived?*/ proc freq data=rupinder.titanic; tables sex /nocum nopercent; where survived=1 and sex = "male"; run; /* 5 How many female passengers over the age of 60 survived?*/ proc freq data=rupinder.titanic; tables sex /nocum nopercent; where survived=1 and sex = "female" and age>60; run; /* 6 How many male passengers over the age of 60 survived?*/ proc freq data=rupinder.titanic; tables sex /nocum nopercent; where survived=1 and sex = "male" and age>50; run; /* 7 How many passengers survived port wise*/ proc freq data=rupinder.titanic; tables embarked /nocum nopercent;

where survived=1 ; run; /* 8 Which class of male passengers survived were more */ proc freq data=rupinder.titanic; tables pclass /nocum nopercent; where sex="male" and survived=1 ; run; /* 9 Which cabin passengers survived more*/ proc freq data=rupinder.titanic; tables cabin /nocum nopercent; where survived = 1; run; /* 10 How many passengers could not survive class wise? */ proc freq data=rupinder.titanic; tables survived*pclass /nocum nopercent norow nocol; run; /* 11 What was the average age of the females who could not survive? */ proc means data=rupinder.titanic mean; var age ; where survived = 0 and sex="female"; run; /* 12 What was the average age of the males who survived?*/ proc means data=rupinder.titanic mean; var age ; where survived = 1 and sex="male"; run; /* 13 What was the maximum age of female passengers survived? */ proc means data=rupinder.titanic max; var age ; where survived = 1 and sex="female"; run; /* 14 Which is more robust method to determine the average age of passengers who could not survive- mean or median? */ proc summary data=rupinder.titanic print max min kurt; var age; run; /* 15 What was the fare of second class passengers for Females who boarded from Queenstown */ proc print data=rupinder.titanic;

var fare ; where sex="female" and embarked="Q" and sibsp=0 and pclass=2; run; /* 16 Divide the data of male and females separately */ Data rupinder.male_titanic rupinder.female_titanic; set rupinder.titanic; if sex="male" then output rupinder.male_titanic; else output rupinder.female_titanic; run; /* 17 Append the two data sets*/ data rupinder.append1; set rupinder.male_titanic rupinder.female_titanic; run; proc append base=rupinder.male_titanic data=rupinder.female_titanic; run; * 18 sort the two data sets on name; proc sort data=rupinder.male_titanic; by name; run; proc sort data=rupinder.female_titanic; by name; run; /* 19 Merge the male and female datasets into one */ DATA rupinder.merge; MERGE rupinder.male_titanic rupinder.female_titanic; BY name; RUN; /* 20 Extract the salutation of passengers from their names */ data rupinder.titanic_new; set rupinder.titanic; salutation= SUBSTR (name, INDEX (name ,',' )+2, INDEX (name ,'.' )-INDEX (name ,',' )); run; proc contents data=rupinder.titanic; run; /* 21 display the fare in dollars upto two decimal places */ data rupinder.titanic_new; set rupinder.titanic_new; format fare dollar10.2; run; /* 22 Prepare a report of the passengers blonging to class 1*/ proc report data= rupinder.titanic; column Name sex age fare; where pclass=1;

run;

Potrebbero piacerti anche