1CopyrightWarningThis material has been reproduced and communicated to you by or on behalf ofFederation University Australia in accordance with Section 113P of the Copyright Act1968 (the Act).The material in this communication may be subject to copyright under the Act. Anyfurther reproduction or communication of this material may be the subject of copyrightprotection under the Act.Do not remove this notice.ITECH3101 –Business Analytics and Decision Supportweek 5Lab Exercise – Introduction of SAS programmingID: Name: __________In this project, you’ll learn how to write your own programs by using SAS.Project 1: Knowing DATA steps and PROC stepsSAS programs consist of DATA steps and PROC steps.In DATA steps, you can create data set and read, write, and manipulate data. ThenDATA steps pass the data to a PROC step for processing. DATA steps begin withkeyword DATA and usually end with a RUN statement.In PROC( short for procedure) steps, you can use built-in procedures to analyze data andcomplete tasks such as writing reports, summarizing data or creating graphical output.PROC steps begin with the word PROC and end with either a RUN or QUIT statement(orboth).Task: Write your first SAS program.Step 1. Get into your SAS Studio, and select CODE tapStep 2. Write code and run program.Step 3. Look at LOG and RESULT.Step 4 Store your program2Download Dataset: celsius.txt from Week 5 in Moodle and save it under myfolders onyour computer.Step 1. Get into your SAS Studio, and select CODE tap.When you open SAS Studio, make sure that you have CODE highlighted. The CODEwindow is a place where you write your SAS program.Step 2. Write code and run program.(1) You may first write the comment with an asterisk and end it with a semicolon. Thecomment will introduce the purpose of the program.3(2) Select Preferences to Enable auto complete functionWhen you type some keywords in the CODE window, SAS Studio shows you syntax andoptions for helping program. You can select or deselect Autocomplete function.45(3) Write code and run the programIn this program:Statement 2 names a data set called Convert.Statement 3 tells the program where original data is located. To read and write databetween SAS Studio session and your hard drive, you need to place your data in aspecific location: SASUniversityEditionmyfolders.You can place SASUniversityEditionmyfloders at location you selected. This location(SASUniversityEditionmyfolders) is mapped to a shared folder called/folders/myfolders in SAS Studio.Statement 4 reads data from the celsius.txt file.Statement 5 uses a formula to convert Celsius to Fahrenheit.Statement 6 ends DATA step.Statement 8 lists the content of data set convert.Statement 9 specifies which variables you want to include in report.Step 3. Look at LOG and RESULT.After running your program, you can have a look at the result of program.6The RESULTS window is place where SAS output appears. Click RESULTS tap:The LOG window displays your program, any syntax errors in the program, informationabout data reading and writing and CPU time used, etc.7Step 4 Save your programFrom CODE tab, select the icon for SAVE AS8SASUSER is a permanent SAS library that is created automatically for each user.This library should have been allocated to the shared folder:SASUniversityEditionmyfolderssasuser.v94.After selecting the Save As and expanding My folders, select assuser.v94 and enterprogram name, and then click on Save button.9Summary of storage of SAS data and program filesA SAS library is a location where SAS data sets and other types of SAS files are stored.1) SASUSER is a permanent SAS library that is created automatically for each user.2) WORK library is a temporary storage location for SAS data sets. It is the defaultlibrary. If you create a SAS data set without specifying a library, SAS will put it in theWORK library, and then delete it when you end your session.3) Create your new libraryClick New Library tap to open new library window.1011In the New library window, type the name of library. In Path field, click the Browsebutton to navigate to the folder or directory where you want your data sets to be stored.12Then click Ok and the library Week2 you just created will appear in Active Librarieswindow.Project 2: Basic programming rulesTask: This project will focus primarily on basic programming rules of SAS, data steppart of SAS and proc step part of SAS.1. Basic Concepts and Rules1) Each statement in SAS must end in a semicolon (;).2) SAS variable names must be 32 characters or less, constructed of letters, digits and theunderscore character.3) SAS is not case sensitive, except inside of quoted strings4) Data set names follow similar rules as variables, but they have a different name space5) Missing values are handled consistently in SAS, and are represented by a period (.).6) Names must start with a letter or an underscore ( _ ).7) Data type. There are two data types: numerical and character.2. SAS programs consist of two types of steps131) DATA (data step):• Begin with DATA statements• Read external (or internal) data files to create SAS datasets• Create new SAS datasets by submerging, merging, modifying, and updating existingSAS data sets.• Create new variables• Analyze, operate or display data• Extract the information• Generate reports or save files to hard disksPlease note that DATA steps execute line by line and observation by observation.(1) Execute line by lineSAS executes line one of your DATA step before it executes line two, and line twobefore line three, and so on.(2) Execute observation by observationSAS takes the firs observation and runs it all the way through the DATA step(line by line) before looping back to pick up the second observation. In this case, SASsees only one observation at a time.DATA steps execute line by line and observation by observation2) PROC (procedure step):PROC STEPS invoke and execute programs through a series of SAS statements. Usuallya data set is used as input data.14(1) begin with PROC statements(2) perform specific analysis or function such as produce summaries of the data(3) produce results or report such as tables, plots and results of statistical analysesSAS contains a vast number of procedure that has been developed over many years andby many teams of programmers.All procedure steps begin with PROC. Overall procedure syntax:PROC procname DATA=dataname;(specific part of program)RUN;Please note that always start by naming the relevant procedure and the data to beanalyzed.Project 3: Example of DATA steps and PROC stepsTask: Make data in SAS.Step 1. Get into your SAS Studio, and select CODE tapStep 2. Write code and run program.Step 3. Look at LOG and RESULT.Step 4 Store your programStep 1. Get into your SAS Studio, and select New icon on the left-hand pane under theServer Files and Folders.15Step 2. Write code and run program.After clicking Run tap, we get16Question 1?In DATA step in the above program, there are two names. Why is there only one row ofdata instead of two rows in OUTUT DATA tab?The reason is that the code did not explicitly output the second set of variables so thesecond set of data is not written out and saved into the dataset.Step 2. Add the second output before the runAfter clicking Run tap, we get17Question 2?In OUTUT DATA tab, the second value of name should have been Steve, but it getstruncated to Stev. Why is the second value for the name variable truncated in OUTUTDATA tab?The reason is that SAS implicitly declared name to be a character based on the Firstinstance ( Mike) and it also implicitly declared the length of character variable based onthe value it had information on (Mike). Therefore, the length was implicitly set to 4. Inthis case, Steve gets truncated to Stev.Step 3. Use length data step statementThere is a dollar sign ($) after the variable name. It indicates that name is declared to be acharacter and its length is 5.18After clicking Run tap, we getStep 3. Explicitly declare the types and lengths of variablesThere is a better way to make data within SAS. For example, we can explicitly declarethe types and lengths of variables. In addition, we can use INPUT and DATALINES orCARDS data step statements to read in multiple rows of data all at once.19After clicking Run tap, we get• length statement explicitly declares the types and lengths of variable: name is acharacter variable and its length is 5. x and y are numeric variables and their length are8.• input statement tells SAS how to read raw data. In this case, this statement tells SASto read three data values from a character variable name and 2 numeric variables xand y.• datalines ( or cards) statement is used to read raw data directly in your SAS programand it must be the last statement in the DATA step.Project 4: Making datasets using SQL type statements1. We can use PROC SQL to make datasets within SAS. There are two basic ways to useSQL with SAS;(1) embed complete SQL statements in the SQL procedure(2) use WHERE statements or WHERE= data set option to select rows in SAS DATAand PROC steps2. Basic form of SQL procedure is:PROC SQL;sql-statement;The possible values for sql-statement in PROC SQL include CREATE, DELETESELECT, UPDATE, etc, with a semicolon stuck on the end.203. SQL does not contain structures like SAS DATA and PROCE steps and operationsperformed by most other SAS procedures don’t exist in SQL.4. In SQL, reports are written automatically whenever you use a SELECT statement.5.PROC SQL can run interactively without a RUN statement.Examples:1) making a new datasetIn the above code, you make a new dataset named sqltry1 in work library with threevariables and no observations or rows.After clicking Run tap, we get2) You can also use PROC SQL to create new datasets through querying a table that21already exists within an existing SAS library.After clicking RESULTS tap, we get22Project 5. Answering questions (Please do this at your home by using your owncomputer)1. List five best practices of dashboard designProject 6. Creating a Professional ReportSummarize the above experiments procedure, results, answering questions andscreenshots (project 1, 2, 3, 4, 5) into one report. Your report is the assignment that isrequired to be submitted for evaluation on week 11. Create a report by following belowsteps.You can add a chapter called Chapter 5 in your previous report.1. Open your last week’s report and find the end of last week’s report.2. Copy this week’s related experimental results, your findings and Screenshots, andpaste them at the end of last week’s report.233. Delete original Table of Content you created.4. Select all content , align all text to both left and right margin5. Use shortcut key approach, generate Chapter 5: Introduction of SASprogramming6. Then use shortcut key approach to generate proper sub-chapters for this week’slab work.7. Insert Table of Contents to your report.
Hi there! Click one of our representatives below and we will get back to you as soon as possible.