SAS Virtual Learning Environment Sessions
SAS Virtual Learning Environment Sessions
com
Lesson 1 Essentials libname '/people/m277325/consult/EPG1V2/data’
/ /
********************************************* *********************************************
**/ */
/* In the line of code below, replace /* You must run SETUP.SAS before you run
FILEPATH */ */
/* with the path to your EPG1V2/data folder /* this code to create your data for EPG1V2
*/ */
/ /*
********************************************* */
**/ /* DO NOT EDIT THE CODE BELOW
*/
%let /
path=/people/m277325/consult/EPG1V2/data;
data myclass; /* Reads sashelp.class table and creates a copy called my class*/ Data Step vs Proc Step
/ set sashelp.class; - Data: creates/edits info for
run; a table
- Proc: processes a table in a
proc print data=myclass; specific, pre-defined way
run; libname statement
libname libref engine “path”;
data work.shoes; libname: creates library
set sashelp.shoes; - Must be <= 8 characters
NetSales=Sales-Returns; /*This creates a new variable*/ - Start w/ letter or _
run; libref: library name
engine: set of instructions
proc means data=work.shoes mean sum maxdec=2; /*This rounds the statistics to 2 decimal path: location
places*/ ex: libname mylib
var NetSales; *Gives us info. about NetSales by region; “s:/workshop/data”;
class region;
Lesson
run; 2 Accessing Data libname '/people/m277325/consult/EPG1V2/data
proc contents data=eu_sport_trade; run; /*And changing the Macros to explore others*/
/*SAS Procedures*/
/*SAS Procedures PROC PRINT*/
proc PRINT data=pg1.storm_summary (obs=10); /*Prints only the first 10 rows*/
var Season Name Basin MaxWindMPH; /*limits the columns included in the report */
/*Ctrl 'select' allows you to choose them from the library, then drag them
over */ run;
length CarType $12; /*length statement needs to be coded BEFORE if-then statements*/
if MSRP<6000 then CarType="Basic";
else CarType="Luxury"; Pay attention to the +1 here when calculating # of days
/** Making new Variables **/
MaxWindKM = MaxWindMPH * 1.60935; /*New Column now called MaxWindKM*/
/*Creating Multiple Output-Tables in one DATA /*Creating Permanant Tables our Tables in the SAS
step*/ Libraries*/
data indian atlantic pacific; /*you can create a permanent table in the
set pg1.storm_summary; EPG1V2/output folder*/
length Ocean $8; libname out "path-to-EPG1V2/output";
keep Basin Season Name MaxWindMPH Ocean; data out.storm_cat5;
Basin=upcase(Basin); . . .
OceanCode=substr(Basin,2,1); run;
if OceanCode="I" then do;
Ocean="Indian"; /*This creates a new storm_new table in the OUT
output indian; library!*/
end; data out.storm_new;
if OceanCode="A" then do; set pg1.storm_summary;
Ocean="Atlantic"; run;
output atlantic;
end;
if OceanCode="P" then do;
Ocean="Pacific";
output pacific;
end;
run;
Lesson 5: Analyzing and Reporting on Data libname '/people/m277325/consult/EPG1V2/data
/*One-Way Frequency Report*/
pro freq. data=pg1.storm_final order=freq nlevels; /*order=freq puts observations in descending order by
frequency*/
tables BasinName Season; /*nlevels adds table at the top to show number of obs*/
run;
proc means data=pg1.storm_detail maxdec=0 median max; /*First sheet is named “South Pacific
Summary*/
class Season;
var Wind;
where Basin='SP' and Season in (2014,2015,2016);
run;
/*Filtering Data with SQL*/ /*Joining tables using SQL inner join*/
title ‘International Storms Since proc sql;
2000’; select class_update.name, grade, age, teacher /*Need this
proc sql; qualifier*/
select propcase(Name) as Name, from pg1.class_update inner join pg1.class_teachers
Age, Height, Birthday format=date9. on class_update.Name=class_teachers.Name;
from pg.class_birthdate quit;
where age > 14 and Height > 156
order by Heigh desc, Name;
quit; /*Assigning an alias*/
title; proc sql;
select u.name, grade, age, teacher
/*Creating a table from a query*/ from pg1.class_updated as u
proc sql; inner join pg1.class_teachers as t
create table work.myclass as on u.name=t.name;
select name, age, height run;
from pg1.class_birthdate
where age > 14
order by height desc;
quit;
Common Formats in SAS