/*Kaz's SAS juku course*/ /*www.estat.us*/ /*DATA steps*/ /*assigning nick names to directories*/ libname kaz_home "c:/temp/"; /*Reading a permanent data and creating a temporary data*/ data ABC; set sashelp.Class; run; /*Reading a temporary data ABC and creating a permanent data ABC*/ data kaz_home.ABC; set ABC; run; /*Keeping variables of your choice*/ data smallABC1; set sashelp.Class; keep name height; run; proc print; title "Keeping only name and height"; run; /*Dropping variables of your choice*/ data smallABC2; set sashelp.Class; drop name height; run; proc print; title "Dropping name and heigh"; run; /*Sorting data sets by a variable*/ proc sort data=ABC out=ABC; by height; run; proc print data=ABC noobs; title "People sorted by height"; var name height weight; run; /*Sorting data sets first by SEX and second by height*/ proc sort data=ABC out=ABC; by sex height; run; proc print data=ABC noobs; title "People sorted by sex and height"; var name sex height weight; run; /*Separating boy's and girls' data and creating two temporary data sets*/ data boys; set ABC; if SEX="M"; run; data girls; set ABC; if SEX="F"; run; proc print data=boys; title "Boys' data"; run; proc print data=girls; title "Girls' data"; run; /*Putting together boys' and girls' data*/ data both_boys_girls; set boys girls; run; /*merging two data sets*/ /*height data*/ data height; set ABC; keep name height; /*weight data*/ data weight; set ABC; keep name weight; /*merging the two back again*/ proc sort data=height;by name;run; proc sort data=weight;by name;run; data both_data; merge height weight; by name; run; proc print;run; /*Creating new variables*/ data ABC2; set sashelp.Class; /*Body mass index BMI, based on height and weight*/ /*http://www.phaster.com/unpretentious/bmi.html says "You can calculate your BMI by dividing your weight in kilograms by the square of your height in meters. In other words the algebraic expression for BMI is: BMI = Kg / (m)2" */ /*First convert height and weight into metric system. Based on the two get Body Mass Index*/ weight_metric=weight*0.45359237; height_metric=(height* 2.54)/100 ; BMI=weight_metric/(height_metric**2); /*Definition of obesity Normal weight = 18.5-24.9 Overweight = 25-29.9 Obesity = BMI of 30 or greater */ length status $ 15; If BMI < 18.5 then status="Underweight"; If BMI => 18.5 and BMI < 25 then status="Normal"; If BMI => 25 and BMI < 30 then status="Overweight"; If BMI >= 30 then status="Obese"; /*creating a sentence, like "John is underweight" based on several variables.*/ x=" is "; sentence=name || x||status; run; proc print data=ABC2 round noobs; title "Body Mass Index for all students"; var name height_metric weight_metric BMI status; run; proc print noobs; title "Sentences"; var sentence; run;