{"id":189,"date":"2020-03-16T21:15:49","date_gmt":"2020-03-17T01:15:49","guid":{"rendered":"http:\/\/pressbooks.library.upei.ca\/montelpare\/?post_type=chapter&#038;p=189"},"modified":"2025-12-17T11:40:53","modified_gmt":"2025-12-17T16:40:53","slug":"components-of-a-sas-session","status":"publish","type":"chapter","link":"https:\/\/pressbooks.library.upei.ca\/montelpare\/chapter\/components-of-a-sas-session\/","title":{"raw":"Components of a SAS Session","rendered":"Components of a SAS Session"},"content":{"raw":"Every SAS session produces three files:\r\n<ul>\r\n \t<li><strong>The SAS code file<\/strong> (.sas): This is the set of instructions that are submitted to the central processing unit of the computer through the SAS engine to generate output (results). You can use the program file editor in SAS Studio to create the .sas file.\u00a0 Your SAS instructions are included in the filename.SAS program file as it is the file that you submit to be processed by the SAS engine which in turn creates output files and log files.<\/li>\r\n<\/ul>\r\nAfter you have successfully started the SAS Studio you will see the image below on your screen. Be sure to select the <strong>SAS Programmer work mode<\/strong> as shown in the image. This is the SAS Studio operation in which you can function as a SAS programmer. In this text, we will use the SAS Studio software to practice statistical analyses for a variety of questions that you may generate in health-related research.\r\n<p style=\"text-align: center\" align=\"center\"><img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2.png\" alt=\"\" class=\"aligncenter wp-image-190 \" width=\"851\" height=\"329\" \/><\/p>\r\n<p class=\"ACaptionHead\" style=\"text-align: center\" align=\"center\"><span lang=\"EN-US\">Figure 8.1 The landing page for SAS Studio in SAS University Edition<\/span><\/p>\r\nNote that there are two work modes in the SAS Studio: 1) SAS Programmer and 2) Visual Programmer. In the examples presented in this text, we selected the SAS Programmer mode (Figure 8.1).\r\n\r\nSAS programs are written to the code page provided within the SAS Studio. The editor function enables you to create the program, submit the program and evaluate the output.\r\n<ul>\r\n \t<li><strong>The output file.<\/strong> In SAS Studio, the output file is accessed from the RESULTS tab of the program editor page, after your SAS code file has been submitted for processing. The RESULTS can be downloaded in the form of either an HTML file \u2013 which you can access through a browser, as a PDF file, or as a word document file \u2013 in RTF format. The output file is what you are trying to produce with your SAS code as it is the file that is generated from the statistical processing of your data. If you should end the session without retrieving the results in one of these formats then it will not be stored, and you will need to resubmit the program in order to view the output.<\/li>\r\n<\/ul>\r\nAfter you have successfully submitted the SAS program you can click on the RESULTS tab to view the output that you have generated with your SAS code.\r\n<p style=\"text-align: center\"><img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3.png\" alt=\"\" class=\"aligncenter wp-image-193 size-full\" width=\"683\" height=\"175\" \/><\/p>\r\n<p class=\"ACaptionHead\" style=\"text-align: center\"><span lang=\"EN-US\">Figure 8.2 Where to find the RESULTS screen for the SAS Studio in SAS University Edition<\/span><\/p>\r\n* <b><i><span style=\"font-size: 9.0pt;font-family: 'Helvetica Neue'\" lang=\"EN-US\">SAS code that runs without errors will generate output in the window shown in Figure 8.1 above.<\/span><\/i><\/b>\r\n<ul>\r\n \t<li><strong>The log file:<\/strong> The LOG file keeps track of what you do in SAS. It is accessed from the LOG tab of the program editor after your SAS code has been processed. The log file is extremely valuable as it details the steps that the <em>SAS engine<\/em> used to generate the results from the series of commands that you entered in your SAS code file. The log file also includes any error messages and warnings that result from the submitted SAS code file. The LOG file presents the specific processing activities of the SAS engine which thereby show you the incorrect syntax or inappropriate command choices and sequences that you may have included in your SAS code file. The SAS LOG file is extremely valuable to you as a programmer as it can show you exactly what you did in the code file that the SAS processing engine didn\u2019t like.<\/li>\r\n<\/ul>\r\nSimilar to the generation of the RESULTS file, after you have successfully submitted the SAS program you can click on the LOG tab to view the processing sequence of the commands that you submitted in your SAS code. All SAS code submissions will generate a LOG file as shown in the image below.\r\n<p style=\"text-align: center\"><img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4.png\" alt=\"\" class=\"aligncenter wp-image-196 size-full\" width=\"793\" height=\"243\" \/><\/p>\r\n<p style=\"text-align: center\">\u00a0Figure 8.3. Log screen for the SAS Studio in SAS University Edition<\/p>\r\n<em>The log file includes any error messages and warnings that result from the submitted SAS code file, allowing you to identify and resolve problems.<\/em>\r\n\r\n<hr \/>\r\n\r\n<h1>Entering Data and Writing a SAS Program<\/h1>\r\nIn the following section, we describe the process of creating a SAS program to analyze data that we have collected.\u00a0 Later we will learn how to import data from several sources as external data sets but for now, we will enter the data by hand.\r\n<h5><strong>Syntax and Variable Type are Important<\/strong><\/h5>\r\n<div>\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Syntax refers to the structure of the language. All computer languages have a specific syntax with distinct rules related to the composition, arrangement and phrasing of commands.\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS programming there are distinct composition and structural arrangement requirements in order for the SAS Processing Engine to understand the code sequence and perform the anticipated analysis.\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS the Statistical Procedures are referred to as Procs \u2013 pronounced \u201cPROCK\u201d\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS all command paragraphs end with a semi-colon\r\n\r\n\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS we <strong>must<\/strong> define all alphanumeric variables by including a $ after the variable name, but we <strong>can<\/strong> include decimal length indicators if we choose when using continuous measures.\r\n\r\n<hr \/>\r\n\r\n<\/div>\r\n<h1>An annotated practice example<\/h1>\r\nLet\u2019s write our first SAS program using data for a simple reaction time experiment.\r\n\r\nIn our experiment, we will use a sample of 5 males and 5 females (total n = 10). We record each participant\u2019s age and their score on a simple reaction time test.\r\n\r\nTo measure reaction time, we drop a meter stick from 1.5m off the floor and have each participant to catch it between their fingers.\r\n\r\nThis simple test has been modified for use in the assessment of reaction time testing for concussed patients and is commonly referred to as the Sideline-Drop stick test<a href=\"#_ftn1\">[1]<\/a>. The score is a measurement in centimetres, of the distance that the metre stick travels between the participant\u2019s fingers from the start of the test to when the participant secured the stick. We can use the distance and the speed of gravity to calculate how quickly each participant grabbed the stick. We can also use distance scores as a proxy measure as we will do in this example, for simplicity.\r\n\r\nThe data we collected for this experiment is shown in the following table:\r\n<table style=\"border-collapse: collapse;width: 65.4114%;height: 348px\" border=\"0\">\r\n<thead>\r\n<tr class=\"shaded\">\r\n<td style=\"width: 25%;height: 47px;text-align: center\">Participant ID<\/td>\r\n<td style=\"width: 12.7822%;height: 47px;text-align: center\">Age in Years<\/td>\r\n<td style=\"width: 9.46222%;height: 47px;text-align: center\">Sex<\/td>\r\n<td style=\"width: 28.7467%;height: 47px;text-align: center\">Reaction time Score<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">1<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">2.3<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">2<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">3.2<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">3<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">22<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">4.2<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">4<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">2.4<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">5<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">23<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">5.8<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">6<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">20<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">4.3<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">7<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">3.6<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">8<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">5.4<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">9<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\r\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">7.5<\/td>\r\n<\/tr>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 25%;height: 15px;text-align: center\">10<\/td>\r\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\r\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\r\n<td style=\"width: 28.7467%;text-align: center\">1.2<\/td>\r\n<\/tr>\r\n<\/thead>\r\n<\/table>\r\n<div>\r\n<p style=\"text-align: center\">Table 8.1\u00a0 Sideline Drop stick Test data for Annotated Practice Example 1<\/p>\r\n\r\n<\/div>\r\n<p style=\"text-align: center\"><img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5.png\" alt=\"\" class=\"aligncenter wp-image-202 size-full\" width=\"716\" height=\"116\" \/><\/p>\r\n<p class=\"ACaptionHead\" style=\"text-align: center\" align=\"center\"><span lang=\"EN-US\">\u00a0Figure 8.4 SAS Studio editor space in SAS University Edition<\/span><\/p>\r\n\r\n\r\n<hr \/>\r\n\r\n<h1>How to Write the SAS Program<\/h1>\r\n<ul>\r\n \t<li>The first line we enter into our SAS program is the<strong> options<\/strong> statement. The options statement tells SAS how to report the results in the output file. Notice that every SAS command statement ends with a semi-colon (;). This is required to tell SAS that the command is complete \u2013 remember, SAS is not magic! You are the programmer (aka coder) and so you need to tell the program what to do.<\/li>\r\n<\/ul>\r\n<div>\r\n<p style=\"text-align: left\"><span style=\"color: #0000ff\">options pagesize=60 linesize=80 center date;<\/span><\/p>\r\n\r\n<\/div>\r\n<code><\/code>\r\n<div>\r\n\r\nThe SAS CODE explained.\r\n\r\n<\/div>\r\n<p style=\"text-align: center\"><img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6.png\" alt=\"\" class=\"aligncenter wp-image-205 size-full\" width=\"679\" height=\"360\" \/><\/p>\r\n\r\n<ul>\r\n \t<li>In line 2 of the program, we name the workspace. Naming the workspace is important so that we can recycle our code and reuse features of programs that we have already written. In other words, you don\u2019t have to start from scratch every time you use SAS. How awesome is that!? To name the workspace use the <strong>data <\/strong>command shown here as:<\/li>\r\n \t<li>Next, we use the <strong>input <\/strong>command to tell SAS where each variable is located in our code file and whether the data are numeric or include text characters (i.e., letters or words). First we type the word INPUT. In SAS we have an entire lexicon of key words that invoke specific functions. INPUT is a KEYWORD that lets the SAS engine know that the text that follows identifies the column headings (aka variable names) the variable types and the width of the column that holds the data for the variable<\/li>\r\n<\/ul>\r\nRecall that our data set for the <strong>reaction time test<\/strong> included the following variables: <strong>participant\u2019s id<\/strong>, <strong>age<\/strong>, <strong>sex<\/strong>, and <strong>reaction time test score<\/strong>. After each variable name, we provide the column numbers where the values for that variable are located. To indicate that a variable includes text characters add a dollar sign $ after the variable name. Don\u2019t forget to include a semi-colon at the end!\r\n<div>\r\n\r\n<span style=\"color: #0000ff\">INPUT ID 1-2 AGE 4-5 SEX $ 7 SCORE 9-11;<\/span>\r\n\r\n<img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp.png\" alt=\"\" class=\"aligncenter wp-image-1344\" width=\"627\" height=\"361\" \/>\r\n<div align=\"center\"><\/div>\r\n<ol>\r\n \t<li>Next we can add a <strong>label <\/strong>statement that will help SAS understand the names of the variables that we used in the SAS program.<\/li>\r\n<\/ol>\r\n<div>\r\n\r\n<span style=\"color: #0000ff\">LABEL ID='PARTICIPANT ID'<\/span>\r\n\r\n<span style=\"color: #0000ff\">SCORE='REACTION TEST SCORE';<\/span>\r\n\r\n<\/div>\r\nThese first few lines of SAS code set up the input environment. There are more commands that we can add in this section, but for now, these are sufficient to enable us to conduct a simple analysis of our data.\r\n<ol start=\"2\">\r\n \t<li>Our next step is to provide the data that SAS will analyze. For this practice example, we will type the data into our SAS code file. In later exercises, we will use external datasets that are saved as separate files and tell SAS where to find it.<\/li>\r\n<\/ol>\r\nThe data entry paragraph begins with the command data lines;<a href=\"#_ftn1\">[1]<\/a>.\r\n\r\nThis command is followed by the data set organized according to the column format that you specified in the input statement above. A semi-colon closes the data paragraph, and the data paragraph is followed by the run; statement.\r\n<div>\r\n<pre><span style=\"color: #0000ff\">DATALINES;\r\n01 21 M 2.3\r\n02 21 F 3.2\r\n03 22 F 4.2\r\n04 21 F 2.4\r\n05 23 F 5.8\r\n06 20 F 4.3\r\n07 21 F 3.6\r\n08 21 F 5.4\r\n09 21 M 7.5\r\n10 21 F 1.2\r\n;<\/span><\/pre>\r\n<\/div>\r\nThe image below illustrates the program up to this point. So far in this program, we have used the following SAS KEYWORDS: DATA, INPUT, LABEL, and DATALINES. Notice also that each SAS COMMAND ends with a semi-colon (;).\r\n\r\n<img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4.jpg\" alt=\"\" class=\"aligncenter wp-image-247 size-full\" width=\"568\" height=\"497\" \/>\r\n<p style=\"text-align: center\">Figure 8.5 How your SAS code file should look<\/p>\r\nNotice the structure of the program. The code itself does not necessarily need to begin in column 1. This is because SAS begins reading at the start of a command line and ends reading when it reaches a semi-colon. However, <strong>the data are intentionally lined up in the left-hand margin<\/strong>, as the column position of the data is important. Correct arrangement and location of the data is essential in order for your program to work properly.\r\n<ol start=\"3\">\r\n \t<li><strong>Be sure to save the code by clicking on the save as icon (it looks like an old-school floppy disk with a pen on it). <\/strong>In SAS there are different ways to store files but <strong>there is no auto-save<\/strong> so if you exit the program without saving you will lose your work. For the most part, the storage\/saving of a file is similar to that which you would use in any end-user application (like a word processor or spreadsheet application).<\/li>\r\n<\/ol>\r\n&nbsp;\r\n\r\nIf this is the first time saving this SAS file, then click the SAVE_AS icon shown here:\r\n\r\nIf you are saving an updated version of the file instead, click the SAVE icon:\r\n\r\nFor this practice example, save the file as <strong>react1.sas<\/strong> in your folder space.\r\n\r\n<img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs.png\" alt=\"\" class=\"aligncenter wp-image-251 size-full\" width=\"470\" height=\"335\" \/>\r\n<p style=\"text-align: center\">Figure 8.6 Using the SAVE-AS feature in the SAS program editor<\/p>\r\nLater, you can retrieve the saved file by locating the file name in your SAS folders. Just select the file and then double click to open the file in your SAS editor.\r\n\r\n<img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve.png\" alt=\"\" class=\"aligncenter wp-image-252 size-full\" width=\"520\" height=\"489\" \/>\r\n<p style=\"text-align: center\">Figure 8.7 Retrieving a saved file for use in the SAS program editor<\/p>\r\nNow that the data is entered and your file is saved we can tell SAS to analyze the data. To do this we write SAS commands that tell the program what to do with the data. These are procedural statements so they each begin with the word <strong>proc<\/strong> (pronounced as \u201cprock\u201d).\r\n<ol start=\"4\">\r\n \t<li>The first thing we want to do is to sort the data so we use the following command: <strong>proc sort<\/strong>.<\/li>\r\n<\/ol>\r\nSo, what are we sorting?\u00a0 Well, we are sorting the data we entered by hand from our reaction test experiment. Recall that the name we gave to the working file was<strong> react<\/strong>, because it represented the reaction test scores for a group of participants.\r\n\r\nLet\u2019s begin by sorting the data by sex and produce a printout of the data we entered. First we write proc sort which tells SAS to sort the data. Then we write <strong>data=react;<\/strong> to tell SAS which data we want it to sort. Finally, we tell it how to sort the data by using the word <strong>by<\/strong> + <em>the name of the variable to sort on<\/em> (in this case, <strong>sex<\/strong>).\r\n<div>\r\n\r\n<span style=\"color: #0000ff\">PROC SORT DATA=REACT; BY SEX;<\/span>\r\n\r\n<span style=\"color: #0000ff\">PROC PRINT; VAR ID AGE SEX SCORE;<\/span>\r\n\r\n<\/div>\r\n<ol start=\"5\">\r\n \t<li>Let\u2019s also compute some basic descriptive statistics on this data using the <strong>proq freq<\/strong> command and the <strong>tables<\/strong> command to produce a frequency table to count the number of females and the number of males in our data set. Shown here:<\/li>\r\n<\/ol>\r\n<div>\r\n\r\n<span style=\"color: #0000ff\">PROC FREQ; TABLES SEX;<\/span>\r\n\r\n<\/div>\r\n<ol start=\"6\">\r\n \t<li>We also want to look at the average scores for the reaction test in the total group. To do this we first use the <strong>proc univariate;<\/strong> command which will tell SAS to provide descriptive statistics. We are only interested in looking at the reaction test score so we indicate this by writing <strong>var<\/strong> + <em>the name of the variable of interest <\/em>(in this case, <strong>score<\/strong>).<\/li>\r\n<\/ol>\r\n<div>\r\n\r\n<span style=\"color: #0000ff\">PROC UNIVARIATE; VAR SCORE;<\/span>\r\n\r\n<\/div>\r\n<ol start=\"7\">\r\n \t<li>Finally, let\u2019s compare the average reaction test scores between male and female participants. To do this we repeat the line of code for the total group but we add a <strong>by<\/strong> statement which tells SAS to apply the procedure based on groupings identified by that variable (in this case, <strong>sex<\/strong>).<\/li>\r\n<\/ol>\r\n<div>\r\n\r\n<span style=\"color: #0000ff\">PROC UNIVARIATE; VAR SCORE; BY SEX;<\/span>\r\n\r\n<\/div>\r\nCongratulations!\u00a0 Your first SAS program is complete and ready to run.\r\n\r\n<img src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete.png\" alt=\"\" class=\"aligncenter wp-image-253 size-full\" width=\"485\" height=\"512\" \/>\r\n<p style=\"text-align: center\">Figure 8.8. The complete program in the SAS program editor<\/p>\r\nSave the program again before you run it. Saving continuously reduces the risk of losing work as you write program code.\r\n<div>\r\n<div>\r\n<h5><a href=\"#_ftnref1\">[1]<\/a> In older versions of SAS the word <code>cards<\/code> was used instead of <code>datalines<\/code>. Notice that the command ends with a semi-colon.<\/h5>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n&nbsp;","rendered":"<p>Every SAS session produces three files:<\/p>\n<ul>\n<li><strong>The SAS code file<\/strong> (.sas): This is the set of instructions that are submitted to the central processing unit of the computer through the SAS engine to generate output (results). You can use the program file editor in SAS Studio to create the .sas file.\u00a0 Your SAS instructions are included in the filename.SAS program file as it is the file that you submit to be processed by the SAS engine which in turn creates output files and log files.<\/li>\n<\/ul>\n<p>After you have successfully started the SAS Studio you will see the image below on your screen. Be sure to select the <strong>SAS Programmer work mode<\/strong> as shown in the image. This is the SAS Studio operation in which you can function as a SAS programmer. In this text, we will use the SAS Studio software to practice statistical analyses for a variety of questions that you may generate in health-related research.<\/p>\n<p style=\"text-align: center; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2.png\" alt=\"\" class=\"aligncenter wp-image-190\" width=\"851\" height=\"329\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2.png 802w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2-300x116.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2-768x297.png 768w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2-65x25.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2-225x87.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas2-350x135.png 350w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/p>\n<p class=\"ACaptionHead\" style=\"text-align: center; text-align: center;\"><span lang=\"EN-US\">Figure 8.1 The landing page for SAS Studio in SAS University Edition<\/span><\/p>\n<p>Note that there are two work modes in the SAS Studio: 1) SAS Programmer and 2) Visual Programmer. In the examples presented in this text, we selected the SAS Programmer mode (Figure 8.1).<\/p>\n<p>SAS programs are written to the code page provided within the SAS Studio. The editor function enables you to create the program, submit the program and evaluate the output.<\/p>\n<ul>\n<li><strong>The output file.<\/strong> In SAS Studio, the output file is accessed from the RESULTS tab of the program editor page, after your SAS code file has been submitted for processing. The RESULTS can be downloaded in the form of either an HTML file \u2013 which you can access through a browser, as a PDF file, or as a word document file \u2013 in RTF format. The output file is what you are trying to produce with your SAS code as it is the file that is generated from the statistical processing of your data. If you should end the session without retrieving the results in one of these formats then it will not be stored, and you will need to resubmit the program in order to view the output.<\/li>\n<\/ul>\n<p>After you have successfully submitted the SAS program you can click on the RESULTS tab to view the output that you have generated with your SAS code.<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3.png\" alt=\"\" class=\"aligncenter wp-image-193 size-full\" width=\"683\" height=\"175\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3.png 683w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3-300x77.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3-65x17.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3-225x58.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas3-350x90.png 350w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/p>\n<p class=\"ACaptionHead\" style=\"text-align: center\"><span lang=\"EN-US\">Figure 8.2 Where to find the RESULTS screen for the SAS Studio in SAS University Edition<\/span><\/p>\n<p>* <b><i><span style=\"font-size: 9.0pt;font-family: 'Helvetica Neue'\" lang=\"EN-US\">SAS code that runs without errors will generate output in the window shown in Figure 8.1 above.<\/span><\/i><\/b><\/p>\n<ul>\n<li><strong>The log file:<\/strong> The LOG file keeps track of what you do in SAS. It is accessed from the LOG tab of the program editor after your SAS code has been processed. The log file is extremely valuable as it details the steps that the <em>SAS engine<\/em> used to generate the results from the series of commands that you entered in your SAS code file. The log file also includes any error messages and warnings that result from the submitted SAS code file. The LOG file presents the specific processing activities of the SAS engine which thereby show you the incorrect syntax or inappropriate command choices and sequences that you may have included in your SAS code file. The SAS LOG file is extremely valuable to you as a programmer as it can show you exactly what you did in the code file that the SAS processing engine didn\u2019t like.<\/li>\n<\/ul>\n<p>Similar to the generation of the RESULTS file, after you have successfully submitted the SAS program you can click on the LOG tab to view the processing sequence of the commands that you submitted in your SAS code. All SAS code submissions will generate a LOG file as shown in the image below.<\/p>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4.png\" alt=\"\" class=\"aligncenter wp-image-196 size-full\" width=\"793\" height=\"243\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4.png 793w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4-300x92.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4-768x235.png 768w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4-65x20.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4-225x69.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas4-350x107.png 350w\" sizes=\"auto, (max-width: 793px) 100vw, 793px\" \/><\/p>\n<p style=\"text-align: center\">\u00a0Figure 8.3. Log screen for the SAS Studio in SAS University Edition<\/p>\n<p><em>The log file includes any error messages and warnings that result from the submitted SAS code file, allowing you to identify and resolve problems.<\/em><\/p>\n<hr \/>\n<h1>Entering Data and Writing a SAS Program<\/h1>\n<p>In the following section, we describe the process of creating a SAS program to analyze data that we have collected.\u00a0 Later we will learn how to import data from several sources as external data sets but for now, we will enter the data by hand.<\/p>\n<h5><strong>Syntax and Variable Type are Important<\/strong><\/h5>\n<div>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Syntax refers to the structure of the language. All computer languages have a specific syntax with distinct rules related to the composition, arrangement and phrasing of commands.<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS programming there are distinct composition and structural arrangement requirements in order for the SAS Processing Engine to understand the code sequence and perform the anticipated analysis.<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS the Statistical Procedures are referred to as Procs \u2013 pronounced \u201cPROCK\u201d<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS all command paragraphs end with a semi-colon<\/p>\n<p>\u2022\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In SAS we <strong>must<\/strong> define all alphanumeric variables by including a $ after the variable name, but we <strong>can<\/strong> include decimal length indicators if we choose when using continuous measures.<\/p>\n<hr \/>\n<\/div>\n<h1>An annotated practice example<\/h1>\n<p>Let\u2019s write our first SAS program using data for a simple reaction time experiment.<\/p>\n<p>In our experiment, we will use a sample of 5 males and 5 females (total n = 10). We record each participant\u2019s age and their score on a simple reaction time test.<\/p>\n<p>To measure reaction time, we drop a meter stick from 1.5m off the floor and have each participant to catch it between their fingers.<\/p>\n<p>This simple test has been modified for use in the assessment of reaction time testing for concussed patients and is commonly referred to as the Sideline-Drop stick test<a href=\"#_ftn1\">[1]<\/a>. The score is a measurement in centimetres, of the distance that the metre stick travels between the participant\u2019s fingers from the start of the test to when the participant secured the stick. We can use the distance and the speed of gravity to calculate how quickly each participant grabbed the stick. We can also use distance scores as a proxy measure as we will do in this example, for simplicity.<\/p>\n<p>The data we collected for this experiment is shown in the following table:<\/p>\n<table style=\"border-collapse: collapse;width: 65.4114%;height: 348px\">\n<thead>\n<tr class=\"shaded\">\n<td style=\"width: 25%;height: 47px;text-align: center\">Participant ID<\/td>\n<td style=\"width: 12.7822%;height: 47px;text-align: center\">Age in Years<\/td>\n<td style=\"width: 9.46222%;height: 47px;text-align: center\">Sex<\/td>\n<td style=\"width: 28.7467%;height: 47px;text-align: center\">Reaction time Score<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">1<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">2.3<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">2<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">3.2<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">3<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">22<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">4.2<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">4<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">2.4<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">5<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">23<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">5.8<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">6<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">20<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">4.3<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">7<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">3.6<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">8<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">5.4<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">9<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">M<\/td>\n<td style=\"width: 28.7467%;height: 15px;text-align: center\">7.5<\/td>\n<\/tr>\n<tr style=\"height: 15px\">\n<td style=\"width: 25%;height: 15px;text-align: center\">10<\/td>\n<td style=\"width: 12.7822%;height: 15px;text-align: center\">21<\/td>\n<td style=\"width: 9.46222%;height: 15px;text-align: center\">F<\/td>\n<td style=\"width: 28.7467%;text-align: center\">1.2<\/td>\n<\/tr>\n<\/thead>\n<\/table>\n<div>\n<p style=\"text-align: center\">Table 8.1\u00a0 Sideline Drop stick Test data for Annotated Practice Example 1<\/p>\n<\/div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5.png\" alt=\"\" class=\"aligncenter wp-image-202 size-full\" width=\"716\" height=\"116\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5.png 716w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5-300x49.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5-65x11.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5-225x36.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas5-350x57.png 350w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/p>\n<p class=\"ACaptionHead\" style=\"text-align: center; text-align: center;\"><span lang=\"EN-US\">\u00a0Figure 8.4 SAS Studio editor space in SAS University Edition<\/span><\/p>\n<hr \/>\n<h1>How to Write the SAS Program<\/h1>\n<ul>\n<li>The first line we enter into our SAS program is the<strong> options<\/strong> statement. The options statement tells SAS how to report the results in the output file. Notice that every SAS command statement ends with a semi-colon (;). This is required to tell SAS that the command is complete \u2013 remember, SAS is not magic! You are the programmer (aka coder) and so you need to tell the program what to do.<\/li>\n<\/ul>\n<div>\n<p style=\"text-align: left\"><span style=\"color: #0000ff\">options pagesize=60 linesize=80 center date;<\/span><\/p>\n<\/div>\n<p><code><\/code><\/p>\n<div>\n<p>The SAS CODE explained.<\/p>\n<\/div>\n<p style=\"text-align: center\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6.png\" alt=\"\" class=\"aligncenter wp-image-205 size-full\" width=\"679\" height=\"360\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6.png 679w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6-300x159.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6-65x34.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6-225x119.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/sas6-350x186.png 350w\" sizes=\"auto, (max-width: 679px) 100vw, 679px\" \/><\/p>\n<ul>\n<li>In line 2 of the program, we name the workspace. Naming the workspace is important so that we can recycle our code and reuse features of programs that we have already written. In other words, you don\u2019t have to start from scratch every time you use SAS. How awesome is that!? To name the workspace use the <strong>data <\/strong>command shown here as:<\/li>\n<li>Next, we use the <strong>input <\/strong>command to tell SAS where each variable is located in our code file and whether the data are numeric or include text characters (i.e., letters or words). First we type the word INPUT. In SAS we have an entire lexicon of key words that invoke specific functions. INPUT is a KEYWORD that lets the SAS engine know that the text that follows identifies the column headings (aka variable names) the variable types and the width of the column that holds the data for the variable<\/li>\n<\/ul>\n<p>Recall that our data set for the <strong>reaction time test<\/strong> included the following variables: <strong>participant\u2019s id<\/strong>, <strong>age<\/strong>, <strong>sex<\/strong>, and <strong>reaction time test score<\/strong>. After each variable name, we provide the column numbers where the values for that variable are located. To indicate that a variable includes text characters add a dollar sign $ after the variable name. Don\u2019t forget to include a semi-colon at the end!<\/p>\n<div>\n<p><span style=\"color: #0000ff\">INPUT ID 1-2 AGE 4-5 SEX $ 7 SCORE 9-11;<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp.png\" alt=\"\" class=\"aligncenter wp-image-1344\" width=\"627\" height=\"361\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp.png 1200w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp-300x173.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp-1024x590.png 1024w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp-768x442.png 768w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp-65x37.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp-225x130.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/codeexp-350x202.png 350w\" sizes=\"auto, (max-width: 627px) 100vw, 627px\" \/><\/p>\n<div style=\"margin: auto;\"><\/div>\n<ol>\n<li>Next we can add a <strong>label <\/strong>statement that will help SAS understand the names of the variables that we used in the SAS program.<\/li>\n<\/ol>\n<div>\n<p><span style=\"color: #0000ff\">LABEL ID=&#8217;PARTICIPANT ID&#8217;<\/span><\/p>\n<p><span style=\"color: #0000ff\">SCORE=&#8217;REACTION TEST SCORE&#8217;;<\/span><\/p>\n<\/div>\n<p>These first few lines of SAS code set up the input environment. There are more commands that we can add in this section, but for now, these are sufficient to enable us to conduct a simple analysis of our data.<\/p>\n<ol start=\"2\">\n<li>Our next step is to provide the data that SAS will analyze. For this practice example, we will type the data into our SAS code file. In later exercises, we will use external datasets that are saved as separate files and tell SAS where to find it.<\/li>\n<\/ol>\n<p>The data entry paragraph begins with the command data lines;<a href=\"#_ftn1\">[1]<\/a>.<\/p>\n<p>This command is followed by the data set organized according to the column format that you specified in the input statement above. A semi-colon closes the data paragraph, and the data paragraph is followed by the run; statement.<\/p>\n<div>\n<pre><span style=\"color: #0000ff\">DATALINES;\r\n01 21 M 2.3\r\n02 21 F 3.2\r\n03 22 F 4.2\r\n04 21 F 2.4\r\n05 23 F 5.8\r\n06 20 F 4.3\r\n07 21 F 3.6\r\n08 21 F 5.4\r\n09 21 M 7.5\r\n10 21 F 1.2\r\n;<\/span><\/pre>\n<\/div>\n<p>The image below illustrates the program up to this point. So far in this program, we have used the following SAS KEYWORDS: DATA, INPUT, LABEL, and DATALINES. Notice also that each SAS COMMAND ends with a semi-colon (;).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4.jpg\" alt=\"\" class=\"aligncenter wp-image-247 size-full\" width=\"568\" height=\"497\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4.jpg 568w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4-300x263.jpg 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4-65x57.jpg 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4-225x197.jpg 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/fig8_4-350x306.jpg 350w\" sizes=\"auto, (max-width: 568px) 100vw, 568px\" \/><\/p>\n<p style=\"text-align: center\">Figure 8.5 How your SAS code file should look<\/p>\n<p>Notice the structure of the program. The code itself does not necessarily need to begin in column 1. This is because SAS begins reading at the start of a command line and ends reading when it reaches a semi-colon. However, <strong>the data are intentionally lined up in the left-hand margin<\/strong>, as the column position of the data is important. Correct arrangement and location of the data is essential in order for your program to work properly.<\/p>\n<ol start=\"3\">\n<li><strong>Be sure to save the code by clicking on the save as icon (it looks like an old-school floppy disk with a pen on it). <\/strong>In SAS there are different ways to store files but <strong>there is no auto-save<\/strong> so if you exit the program without saving you will lose your work. For the most part, the storage\/saving of a file is similar to that which you would use in any end-user application (like a word processor or spreadsheet application).<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>If this is the first time saving this SAS file, then click the SAVE_AS icon shown here:<\/p>\n<p>If you are saving an updated version of the file instead, click the SAVE icon:<\/p>\n<p>For this practice example, save the file as <strong>react1.sas<\/strong> in your folder space.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs.png\" alt=\"\" class=\"aligncenter wp-image-251 size-full\" width=\"470\" height=\"335\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs.png 470w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs-300x214.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs-65x46.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs-225x160.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/saveAs-350x249.png 350w\" sizes=\"auto, (max-width: 470px) 100vw, 470px\" \/><\/p>\n<p style=\"text-align: center\">Figure 8.6 Using the SAVE-AS feature in the SAS program editor<\/p>\n<p>Later, you can retrieve the saved file by locating the file name in your SAS folders. Just select the file and then double click to open the file in your SAS editor.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve.png\" alt=\"\" class=\"aligncenter wp-image-252 size-full\" width=\"520\" height=\"489\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve.png 520w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve-300x282.png 300w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve-65x61.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve-225x212.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/retrieve-350x329.png 350w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/p>\n<p style=\"text-align: center\">Figure 8.7 Retrieving a saved file for use in the SAS program editor<\/p>\n<p>Now that the data is entered and your file is saved we can tell SAS to analyze the data. To do this we write SAS commands that tell the program what to do with the data. These are procedural statements so they each begin with the word <strong>proc<\/strong> (pronounced as \u201cprock\u201d).<\/p>\n<ol start=\"4\">\n<li>The first thing we want to do is to sort the data so we use the following command: <strong>proc sort<\/strong>.<\/li>\n<\/ol>\n<p>So, what are we sorting?\u00a0 Well, we are sorting the data we entered by hand from our reaction test experiment. Recall that the name we gave to the working file was<strong> react<\/strong>, because it represented the reaction test scores for a group of participants.<\/p>\n<p>Let\u2019s begin by sorting the data by sex and produce a printout of the data we entered. First we write proc sort which tells SAS to sort the data. Then we write <strong>data=react;<\/strong> to tell SAS which data we want it to sort. Finally, we tell it how to sort the data by using the word <strong>by<\/strong> + <em>the name of the variable to sort on<\/em> (in this case, <strong>sex<\/strong>).<\/p>\n<div>\n<p><span style=\"color: #0000ff\">PROC SORT DATA=REACT; BY SEX;<\/span><\/p>\n<p><span style=\"color: #0000ff\">PROC PRINT; VAR ID AGE SEX SCORE;<\/span><\/p>\n<\/div>\n<ol start=\"5\">\n<li>Let\u2019s also compute some basic descriptive statistics on this data using the <strong>proq freq<\/strong> command and the <strong>tables<\/strong> command to produce a frequency table to count the number of females and the number of males in our data set. Shown here:<\/li>\n<\/ol>\n<div>\n<p><span style=\"color: #0000ff\">PROC FREQ; TABLES SEX;<\/span><\/p>\n<\/div>\n<ol start=\"6\">\n<li>We also want to look at the average scores for the reaction test in the total group. To do this we first use the <strong>proc univariate;<\/strong> command which will tell SAS to provide descriptive statistics. We are only interested in looking at the reaction test score so we indicate this by writing <strong>var<\/strong> + <em>the name of the variable of interest <\/em>(in this case, <strong>score<\/strong>).<\/li>\n<\/ol>\n<div>\n<p><span style=\"color: #0000ff\">PROC UNIVARIATE; VAR SCORE;<\/span><\/p>\n<\/div>\n<ol start=\"7\">\n<li>Finally, let\u2019s compare the average reaction test scores between male and female participants. To do this we repeat the line of code for the total group but we add a <strong>by<\/strong> statement which tells SAS to apply the procedure based on groupings identified by that variable (in this case, <strong>sex<\/strong>).<\/li>\n<\/ol>\n<div>\n<p><span style=\"color: #0000ff\">PROC UNIVARIATE; VAR SCORE; BY SEX;<\/span><\/p>\n<\/div>\n<p>Congratulations!\u00a0 Your first SAS program is complete and ready to run.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete.png\" alt=\"\" class=\"aligncenter wp-image-253 size-full\" width=\"485\" height=\"512\" srcset=\"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete.png 485w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete-284x300.png 284w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete-65x69.png 65w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete-225x238.png 225w, https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-content\/uploads\/sites\/49\/2020\/03\/complete-350x369.png 350w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/p>\n<p style=\"text-align: center\">Figure 8.8. The complete program in the SAS program editor<\/p>\n<p>Save the program again before you run it. Saving continuously reduces the risk of losing work as you write program code.<\/p>\n<div>\n<div>\n<h5><a href=\"#_ftnref1\">[1]<\/a> In older versions of SAS the word <code>cards<\/code> was used instead of <code>datalines<\/code>. Notice that the command ends with a semi-colon.<\/h5>\n<\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"author":56,"menu_order":1,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-189","chapter","type-chapter","status-publish","hentry"],"part":180,"_links":{"self":[{"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/chapters\/189","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/wp\/v2\/users\/56"}],"version-history":[{"count":25,"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/chapters\/189\/revisions"}],"predecessor-version":[{"id":192,"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/chapters\/189\/revisions\/192"}],"part":[{"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/parts\/180"}],"metadata":[{"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/chapters\/189\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/wp\/v2\/media?parent=189"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/pressbooks\/v2\/chapter-type?post=189"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/wp\/v2\/contributor?post=189"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/pressbooks.library.upei.ca\/montelpare\/wp-json\/wp\/v2\/license?post=189"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}