An_introduction_to_SAS__Part_2_

An_introduction_to_SAS__Part_2_ - An Introduction to SAS...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
An Introduction to SAS data patientdata; input id $ gender $ age height weight pre_bp post_bp; cards; B23 M 55 72 165 145 120 C32 F 63 64 123 165 132 C19 M 68 78 160 162 145 D55 M 70 73 240 180 165 A96 M 64 71 255 155 134 B11 F 73 63 180 151 143 A08 F 59 . 175 172 141 E49 M 61 75 210 149 129 A77 F 82 63 162 166 130 E05 F 69 65 151 165 139 ; run; data patientdata2; set patientdata; average_score = (pre_bp + post_bp)/2; diff_score = pre_bp - post_bp; weight_kg = weight*0.4536; height_m = height/39.37; bmi = weight_kg/(height_m**2); log_bmi = log(bmi); if id='D55' then age=71; if 0 <= bmi < 18.5 then delete; if bmi >= 30 then obese = 'Y'; else obese = 'N'; if age <= 55 then age_group=1; else if 55 < age <= 65 then age_group=2; else if age > 65 then age_group=3; drop weight height; run; proc print data=patientdata2; run; We now continue learning SAS programming by building off of this program and adding a variety of SAS procedure statements. SAS Procedures SAS statements that request predefined routines are called procedures . SAS procedures are the means by which we will examine and analyze the data. All procedures have the same basic syntax: proc procname options; statement / statement options; statement / statement options; run;
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
The word proc is followed by the name of the procedure. In this SAS statement, we may also include one or more options, many of which are specific to the SAS procedures being used. The most common option specifies the data set to be used within the procedure. If this is not specified, the default data set to be used is the one most recently created. We begin with one of the simplest procedures, proc print , which was used in the first part. Proc Print This procedure prints the data for a given working data set. proc print data=patientdata2; run; The above statement will print all variables in the data set patientdata2 . It is often desired to print only a subset of the variables contained in the data set especially in cases where the data set is made up of many variables. This may be done by use of a var statement. If we wish to print only the id and bmi variables from our data set, we use the statements, proc print data=patientdata2; var id bmi; run; It is often a good idea to print the working data set a few times as data is manipulated in order to verify SAS is doing what we think it is. Proc Sort This procedure serves the purpose of sorting a given data set by one or more of the variables within the data set in ascending order (smallest to largest). The sorting variable(s) are specified using a by statement. If the key word descending is put in front of a sort variable, the order of sorting is reversed for that particular variable.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern