CS计算机代考程序代写 Excel Hive DSC201/401 Lecture Spring 2021

DSC201/401 Lecture Spring 2021
Statistical Analysis System (SAS)
Instructor: Will DiGrazio, MS, MBA

Q &A
Questions:
1. You have a text file called stocks.txt containing a stock symbol, a price, and the number of shares. Here are some sample lines of data:
File stocks.txt
AMGN 67.66 100
DELL 24.60 200 GE 34.50 100 HPQ 32.32 120 IBM 82.25 50 MOT 30.24 100
a) Using this raw data file, create a temporary SAS data set (Portfolio). Choose your own variable names for the stock symbol, price, and number of shares. In addition, create a new variable (call it Value) equal to the stock price times the number of shares. Include a comment in your program describing the purpose of the program, your name, and the date the program was written.
b) Write the appropriate statements to compute the average price and the average number of shares of your stocks. Also, identify the total number of shares listed for all of the stocks in the file.

Q &A
Answers: *————————————————————————————————-* | Program name: mystocks.sas in /home/yourNetID/Desktop/MySAS/Data/ | | Purpose: Read in raw data on stock prices and compute values | | Programmer: You | | Date: March 2021 | *————————————————————————————————-*; *Code for item a);
data portfolio;
infile ‘/home/yourNetID/Desktop/MySAS/Data/stocks.txt’; input Symbol $ Price Number;
Value = Number*Price;
run;
title “Listing of Portfolio”;
proc print data=portfolio noobs;
run;
*Code for item b);
title “Means and Sums of Portfolio Variables”; proc means data=portfolio n mean sum maxdec=1;
var Price Number; run;

Pause

BlueHive SAS Walk Through

Pause

Let’s Get Started

Use FastX To Connect To BlueHive • Walk through the instructions at https://info.circ.rochester.edu/BlueHive/FastX.html

Use FastX To Connect To BlueHive
• After logging in with your credentials and accepting the DUO request, select the launch session button

Use FastX To Connect To BlueHive • SelecttheDefaulticonandthenclicktheblueLaunchbutton

Use FastX To Connect To BlueHive • ClicktheblueClosebutton

Use FastX To Connect To BlueHive
• Click the blue font mate-session link in order to open a BlueHive compute session – NOTICE this particular compute session is on the BHC0087 compute node

Open SAS On BlueHive (Option 1) • Open up a terminal session so that we can invoke SAS on a compute node

Open SAS On BlueHive (Option 1) • At the command prompt, type: module load sas

Open SAS On BlueHive (Option 1) • At the command prompt, type: sas

Initial SAS Software • Close the Change Notice window by clicking the close button

SAS Programming
TODAY’S OBJECTIVES)
• Data Step Processing (Reading raw data from external files)
• Creating Permanent SAS Data Sets
• TheLIBNAMEStatement
• PROCCONTENTS
• SASExplorer
• PROCPRINT
• SASVIEWTABLEWindow
• GraphicalOutput
• PROC Means Expanded
• ConditionalLogic
• DO Loops
• PROCLogistic

Data Step Processing
Specifying Missing Values with List Input
• What would happen if you didn’t have a value for Age for the second subject in your file?
• You need a way to tell SAS that there is a missing value for Age in the second line and one way to do this is to use a period to represent the missing value
• You must separate the period from the values around it by one or more spaces because a space is the default delimiter character
• You can use a period to represent a missing character or numeric value when you use the list input method
Original Hypothetical
Answer
X
.

Data Step Processing Reading Data Values Separated by Commas (CSV Files)
▪ ▪ ▪ ▪
▪ ▪ ▪
data demographics1;
infile ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’ dsd; input Gender $ Age Height Weight;
run;
title “Demographics 1 Data Set output”; proc print data=demographics1;
run;

Data Step Processing Reading Data Values Separated by Commas (CSV Files)
▪ ▪ ▪ ▪
data demographics1;
infile ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’ dsd; input Gender $ Age Height Weight;
run;
• Notice the INFILE statement in this example. The DSD (delimiter-sensitive data) following the file name is an INFILE option.
• It performs several functions:
• First, it changes the default delimiter from a blank to a comma
• Next, if there are two delimiters in a row, it assumes there is a missing value between
• Finally, if character values are placed in quotes (single or double quotes), the quotes are stripped from the value
• The INPUT statement uses the list input method

Data Step Processing Using an Alternative Method to Specify an External File
▪ *Using a FILENAME statement to identify an external file;
▪ filename sharks ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’;
▪ data demographics2;
▪ infile sharks dsd;
▪ input Gender $ Age Height Weight; ▪ run;
• The INFILE statement in the last example used the actual file name (placed in quotes) to specify your raw data file
• This alternative method uses a separate FILENAME statement to identify the file and also uses this reference (which is called a fileref) in your INFILE statement, instead of the actual file name itself
• The name following the FILENAME statement (sharks, in this example) is an alias for the actual file name

Data Step Processing
Reading Data Values Separated by Delimiters Other Than Blanks or Commas
▪ ▪
▪ ▪ ▪ ▪
*Using a FILENAME statement to identify an external file;
filename sharks ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’;
data demographics3;
infile sharks dlm=‘:’;
input Gender $ Age Height Weight;
run;
• The abbreviation dlm stands for delimiter and specifies what the delimiter in the file will be to separate the variables

Data Step Processing
Reading Data Values Separated by Delimiters Other Than Blanks or Commas
▪ ▪
▪ ▪ ▪ ▪
*Using a FILENAME statement to identify an external file;
filename sharks ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’;
data demographics4;
infile sharks delimiter=‘:’;
input Gender $ Age Height Weight;
run;
• You can spell out the name of the DELIMITER= option instead of using the abbreviation DLM= if you prefer.

Data Step Processing
Reading Data Values Separated by Delimiters Other Than Blanks or Commas
▪ ▪
▪ ▪ ▪ ▪
• This combination of options performs all the actions requested by the DSD option but overrides the default delimiter for DSD (a comma) with a delimiter of your choice (in this case a colon)
*Using a FILENAME statement to identify an external file;
filename sharks ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’;
data demographics5;
infile sharks dsd dlm=‘:’;
input Gender $ Age Height Weight;
run;
• You can use the DSD and DLM= options together

How do you input a tab delimited file?

Data Step Processing
Reading Data Values Separated by Delimiters Other Than Blanks or Commas
▪ ▪
▪ ▪ ▪ ▪
*Using a FILENAME statement to identify an external file;
filename sharks ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’;
data demographics6;
infile sharks dlm=?????;
input Gender $ Age Height Weight;
run;
• Tabs present an interesting problem because what character do you place between the quotes on the DLM= option? You cannot click the TAB key.

Pause

Data Step Processing
Reading Data Values Separated by Delimiters Other Than Blanks or Commas
▪ ▪
▪ ▪ ▪ ▪
*Using a FILENAME statement to identify an external file;
filename sharks ‘/home/yourNetID/Desktop/MySAS/Data/mydata.csv’;
data demographics6;
infile sharks dlm=‘09’x;
input Gender $ Age Height Weight;
run;
• Tabs present an interesting problem because what character do you place between the quotes on the DLM= option? You cannot click the TAB key.
• Instead, represent the tab value by its hexadecimal equivalent (for American Standard Code for International Interchange – ASCII files), which is the coding method used on Windows platforms and UNIX operating systems, you would use the ‘09’x representation

Data Step Processing
Reading Data Values Separated by Delimiters Other Than Blanks or Commas

Data Step Processing Placing Data Lines Directly in Your Program (the DATALINES Statement)
▪ *Using a DATALINES statement to capture data;
▪ data demographics7;
▪ input Gender $ Age Height Weight;
▪ datalines;
▪ M 50 68 155
▪ F 23 60 101
▪ M 65 72 220
▪ F 35 65 133
▪ M 15 71 166 ▪;
• Suppose you want to write a short test program in SAS. Instead of having to place your data in an external file, you can place your lines of data directly in your SAS program by using a DATALINES statement.
• As seen from the example, the INFILE statement was removed and a DATALINES statement was added.
• Following DATALINES are your lines of data and a semicolon is used to end the DATA step. (Note: You may
either use a single semicolon or a RUN statement to end the DATA step.)
• The lines of data must be the last element in the DATA step (any assignment statement must come before the lines of data).

Data Step Processing
Specifying INFILE Options with the DATALINES Statement *Using a DATALINES statement to capture data along with the INFILE option;








▪ ▪;
data demographics8;
infile datalines dsd;
input Gender $ Age Height Weight; datalines;
“M”,50,68,155 “F”,23,60,101 “M”,65,72,220 “F”,35,65,133 “M”,15,71,166
• What if you use DATALINES and want to use one or more of the INFILE options, such as DLM= or DSD (Delimiter-Sensitive Data)?
• You can use many of the INFILE options with DATALINES by using a reserved file reference called DATALINES.
• For example, if you wanted to run the demographics program without an external data file, you could use the program above

Data Step Processing Raw Data from Fixed Columns (Fixed Input Method)
• In the bank.txt file you have data as follows:

Raw Data from Fixed Columns (Fixed Input Method) *Inputting data into a SAS Data Set from fixed column data;
▪ data financial;
▪ infile ‘/home/yourNetID/Desktop/MySAS/Data/bank.txt’;
▪ input Subj $ 1-3
▪ DOB $ 4-13
▪ Gender $ 14
▪ Balance 15-21;
▪ run;
Notice DOB is input as a character. What would we do if we wanted DOB to be formatted as a Date?
Data Step Processing
• As seen from this example, you specify a variable name, a dollar sign if the variable is a character value, the starting column, and the ending column (if the value takes more than one column).
• In this program, the number of columns you specify for each character variable determines the number of bytes SAS uses to store these values; for numeric variables, SAS will always use 8 bytes to store these values, regardless of how many columns you specify in your INPUT statement.
• There are advanced techniques to change the storage length for numeric variables—and these techniques should be used only when you need to save storage space and you understand the possible problems that can result.

Data Step Processing
Reading Raw Data from Fixed Columns (Formatted Input Method) *Inputting formatted data into a SAS Data Set from fixed column data;
data financial;
infile ‘/home/yourNetID/Desktop/MySAS/Data/bank.txt’; input @1 Subj $3.
@4 DOB mmddyy10.
@14 Gender $1.
@15 Balance 7.;
run;
• Formatted input also reads data from fixed columns. It can read both character and standard numeric data as well as nonstandard numerical values, such as numbers with dollar signs and commas, and dates in a variety of formats.
• Formatted input is the most common and powerful of all the input methods. Any time you have nonstandard data in fixed columns, you should consider using formatted input to read the file.

Data Step Processing
Reading Raw Data from Fixed Columns (Formatted Input Method) *Inputting formatted data into a SAS Data Set from fixed column data;
data financial;
infile ‘/home/yourNetID/Desktop/MySAS/Data/bank.txt’; input @1 Subj $3.
@4 DOB mmddyy10.
@14 Gender $1.
@15 Balance 7.;
run;
• The @ (at) signs in the INPUT statement are called column pointers
• For example, @4 says to SAS, go to column 4.
• Following the variable names are SAS informats. Informats are built-in instructions that tell SAS how to read a data value.
• The choice of which informat to use is dictated by the data.

Data Step Processing
Reading Raw Data from Fixed Columns (Formatted Input Method) *Inputting formatted data into a SAS Data Set from fixed column data;
data financial;
infile ‘/home/yourNetID/Desktop/MySAS/Data/bank.txt’; input @1 Subj $3.
@4 DOB mmddyy10.
@14 Gender $1.
@15 Balance 7.;
run;
• Two of the most basic informats are w.d and $w.
• The w.d format reads standard numeric values. The w tells SAS how many columns to read. The optional d tells SAS that there is an implied decimal point in the value.
• For example, if you have the number 123 and you read it with a 3.0 informat, SAS stores the value 123. If you read the same number with a 3.1 informat, SAS stores the value 12.3.

Data Step Processing
Reading Raw Data from Fixed Columns (Formatted Input Method) *Inputting formatted data into a SAS Data Set from fixed column data;
data financial;
infile ‘/home/yourNetID/Desktop/MySAS/Data/bank.txt’; input @1 Subj $3.
@4 DOB mmddyy10.
@14 Gender $1.
@15 Balance 7.;
run;
• If the number you are reading already has a decimal point in it (this counts as one of the columns to be read), SAS ignores the d portion of the informat. So, if you read the value 1.23 with a 4.1 informat, SAS stores a value of 1.23.
• The $w. informat tells SAS to read w columns of character data. In this program, Subj is read as character data and takes up three columns; values of Gender take up a single column.

Data Step Processing

Data Step Processing
Reading Raw Data from Fixed Columns (Formatted Input Method) *Inputting formatted data into a SAS Data Set from fixed column data;
data financial;
infile ‘/home/yourNetID/Desktop/MySAS/Data/bank.txt’; input @1 Subj $3.
@4 DOB mmddyy10.
@14 Gender $1.
@15 Balance 7.;
run;
• Now it’s time to read the date. The MMDDYY10. informat tells SAS that the date you are reading is in the mm/dd/yyyy form. SAS reads the date and converts the value into a SAS date.

Now Let’s Look At The Output

Data Step Processing Reading Raw Data from Fixed Columns (Formatted Input Method)
• Why is the DOB variable not in a date format?

Data Step Processing Reading Raw Data from Fixed Columns (Formatted Input Method)
• SAS stores dates as numeric values equal to the number of days from January 1, 1960
• So, if you read the value 01/01/1960 with the MMDDYY10. informat, SAS stores a
value of 0
• The date 01/02/1960 read with the same informat would result in a value of 1, and so forth.
• SAS knows all about leap years and correctly converts any date from 1582 to way into the future (1582 is the year Pope Gregory started the Gregorian calendar—dates before this are not defined in SAS).

The Output Was Ugly How Do We Fix It?

Data Step Processing Reading Raw Data from Fixed Columns (Formatted Input Method)
• Question: How do we uncomment lines 00011 and 00012?

Data Step Processing Reading Raw Data from Fixed Columns (Formatted Input Method)
• Better Output from formatting in the PROC Print statement using the format statement
After removing the *; comment characters for lines 00011 and 00012, don’t forget that the format statement still needs to be terminated with a semi-colon after the dollar11.2 informat

Data Step Processing Reading Raw Data from Fixed Columns (Formatted Input Method)
• Alternative Output from formatting in the PROC Print statement using the date9. informat

Data Step Processing Reading Raw Data from Fixed Columns (Formatted Input Method)
• Use the format statement in the data step after the input statement to not have to use it in the PROC Print statements
Notice the Data Set name in this SAS Program is financial2, which demonstrates that it is not simply the same output from the previous examples using the Data Set called financial

Pause

Making SAS Data Sets Permanent

Creating Permanent SAS Data Sets
• SAS procedures cannot read raw data files or spreadsheets directly, so they need the data in SAS data sets.
• Since SAS DATA steps create SAS data sets, we can use this step to change a temporary SAS Data Set that exists in the Work library into a permanent SAS Data Set that resides in a user defined library

Creating Permanent SAS Data Sets
• When you write a DATA statement such as data test;
• SAS creates a temporary SAS data set called Test. When you close your SAS session, this data set disappears
• SAS data set names actually have two-part names in the form: libref.data-set-name
• The part of the name before the period is called a libref (short for library reference), and this tells SAS where to store (or retrieve) the data set
• The part of the name after the period identifies the name you want to give the data set

Creating Permanent SAS Data Sets
• All that is required to make your SAS data sets permanent is to create your own libref using a LIBNAME statement and use that libref in the two-level SAS data set name
• The LIBNAME statement starts with the LIBNAME keyword and then specifies the name of the library (called a libref), followed by the directory or folder where you want to store your permanent SAS data sets
• The libref you use must not be more than 8 characters in length and must be a valid SAS name

The LIBNAME Statement • Create a permanent SAS data set called demog in your /MySAS/Data/ folder

▪ ▪ ▪ ▪
libname My1stLib ‘/home/yourNetID/Desktop/MySAS/Data/’;
data My1stlib.demog;
infile “/home/yourNetID/Desktop/MySAS/Data/mydata.txt”; input Gender $ Age Height Weight;
run;
• The LIBNAME statement starts with the LIBNAME keyword and then specifies the name of the library (called a libref), followed by the directory or folder where you want to store your permanent SAS data sets
• The libref you use must not be more than 8 characters in length and must be a valid SAS name
• When you run this program, data set demog becomes a permanent SAS data set in the
/home/yourNetID/Desktop/MySAS/Data folder
• It is important to remember that any libref that you create exists only for your current SAS session
• If you open a new SAS session, you need to reissue a new LIBNAME statement. A good way to think of a libref is as an alias for the name of the folder (on Windows or UNIX platforms)
• If a libref is created from within a SAS program, it exists only during the session in which it is created. If a libref is created interactively, by using the New Library dialog box, you can select Enable at Start up to make it a permanent libref.

The LIBNAME Statement
Notice the My1stLib Library has been created
The demog Data Set is in the My1stLib Library
Why are there other Data Sets in this newly
created Library?

The LIBNAME Statement & The Set Statement

The LIBNAME Statement

PROC Contents
Use PROC CONTENTS to examine the descriptor portion of a SAS Data Set
▪ title “The Descriptor Portion of Data Set demog”; ▪ proc contents data=My1stLib.demog;
▪ run;
• The output displays information about the data set, such as the number of variables, the number of observations, and the creation and modification dates
• It also displays information about the SAS version used to create the data set and it displays information on each of the variables in the data set, such as the variable name, type, and storage length

PROC Contents
Ordered Alphabetically
Notice we do not need to use the libname statement in this SAS Program because we are still in the same SAS session and My1stLib still exists

PROC Contents
Use PROC CONTENTS to examine the descriptor portion of a SAS Data Set
▪ title “The Descriptor Portion of Data Set demog”; ▪ proc contents data=My1stLib.demog varnum;
▪ run;
• A more useful way to list variable information is to list them in the order the variables are stored in the SAS data set, rather than alphabetically.
• To create such a list, use the VARNUM option of PROC CONTENTS

PROC Contents
When the Data Set was created, this was the order of the variables input
data My1stlib.demog;
infile “/home/yourNetID/Desktop/MySAS/Data/mydata.txt”; input Gender $ Age Height Weight;
run;

SAS Explorer
• Close the SAS: Explorer window that opened initially when you started SAS

SAS Explorer
• Open the SAS: Explorer window by clicking the Explorer icon in the SAS: Toolbox
Or you could select View ➔ Show Tree in the SAS: Explorer menu

SAS Explorer
• Right click on the demog Data Set in the My1stLib library and select View Columns

SAS Explorer
• The Columns tab displays the same information as PROC Contents varnum output

SAS Explorer
• The Details tab displays some of the same information as the PROC Contents output

PROC Print
• Use PROC Print to view the values of your Data Sets ▪ title “Complete Listing of My1stLib.demog”;
▪ proc print data=My1stLib.demog;
▪ run;

PROC Print
• Use PROC Print to view the values of your Data Sets ▪ title “Complete Listing of My1stLib.demog”;
▪ proc print data=My1stLib.demog (obs=5);
▪ run;

PROC Print • Use PROC Print to view the values of your Data Sets
▪ ▪ ▪ ▪ ▪
title “Select Listing of My1stLib.demog”; proc print data=My1stLib.demog noobs;
var Gender Age Weight;
Where Gender=“M”; run;

SAS Viewtable
Viewing the Data Portion of a SAS Data Set Using the SAS VIEWTABLE Window Simply left double click on the Data Set of choice in the SAS: Explorer window

Graphical Output
• Use PROC GPLOT to graph the function Y = 2x^3 – 5x^2 + 15x – 8 from x=-10 to x = 10

Graphical Output • Use PROC GCHART to produce a simple bar chart

Graphical Output • Use PROC GCHART to produce a simple bar chart

PROC Means Expanded
New Data Set called binary where a student was either admitted to graduate school (1) or not (0)

PROC Means Expanded • Use PROC Means with all of the defaults

PROC Means Expanded • Partial list of PROC MEANS options

PROC Means Expanded
• Use PROC Means with specific options and for specific variables

PROC Means Expanded
• Use PROC Means with specific options and for specific variables as sorted and categorized by the admit variable

Pause

Conditional Statements: (If & Else If)
• Two of the basic tools for conditional processing are the IF and ELSE IF statements
Note: If the and not missing(age) function is not used then the blank age observations will be given an AgeGroup value of 1, which is wrong
Note: All 4 of the IF statements get evaluated even if the first IF condition is met to be true (this is inefficient)
Data conditional;
Length Gender $ 1
Quiz $ 2;
input Age Gender Midterm Quiz FinalExam;
if Age lt 20 and not missing(age) then AgeGroup = 1; if Age ge 20 and Age lt 40 then AgeGroup = 2;
if Age ge 40 and Age lt 60 then AgeGroup = 3;
if Age ge 60 then AgeGroup = 4;
Datalines;
21 M 80 B- 82 . F 90 A 93 35 M 87 B+ 85 48 F. . 76 59 F 95 A+ 97 15 M 88 . 93 67 F 97 A 91 . M 62 F 67 35 F 77 C- 77 ;
Title ‘Listing of Conditional’; Proc print data=conditional noobs; Run;

Conditional Statements: (If & Else If) • Logical Comparison Operators

Conditional Statements: (If & Else If)
• Two of the basic tools for conditional processing are the IF and ELSE IF statements
Note: When any of the
IF statements are true,
else if
else if
else if
Age ge 20 and Age lt 40 then AgeGroup = 2; Age ge 40 and Age lt 60 then AgeGroup = 3; Age ge 60 then AgeGroup = 4;
all of the following ELSE Datalines;
Data conditional;
Length Gender $ 1
Quiz $ 2;
input Age Gender Midterm Quiz FinalExam;
if Age lt 20 and not missing(age) then AgeGroup = 1;
statements are not evaluated, which saves processing time.
21 M 80 B- 82
. F 90 A 93
35 M 87 B+ 85 48 F. . 76 59 F 95 A+ 97 15 M 88 . 93 67 F 97 A 91 . M 62 F 67 35 F 77 C- 77 ;
Title ‘Listing of Conditional’; Proc print data=conditional noobs;
var Age Gender Midterm Quiz FinalExam AgeGroup; Run;

Conditional Statements: (If & Else If)
• Cleaner Version
Data conditional;
Length Gender $ 1
Quiz $ 2;
input Age Gender Midterm Quiz FinalExam;
if missing(age) then AgeGroup = .;
else if
else if
else if
else if
Age lt 20 then AgeGroup
Age lt 40 then AgeGroup
Age lt 60 then AgeGroup
Age ge 60 then AgeGroup
= 1;
= 2;
= 3;
= 4;
Datalines;
21 M 80 B- 82 . F 90 A 93 35 M 87 B+ 85 48 F. . 76 59 F 95 A+ 97 15 M 88 . 93 67 F 97 A 91 . M 62 F 67 35 F 77 C- 77 ;
Title ‘Listing of Conditional’; Proc print data=conditional noobs;
var Age Gender Midterm Quiz FinalExam AgeGroup; Run;

Looping: (Do group)
• All statements between DO and END form a DO group. When the IF condition is true, all of the statements in the DO group execute. A good way to think of this structure is, “If the condition is true, then do the following statements until you reach the end.”
Data grades;
Length Gender $ 1
Quiz $2
AgeGrp $ 13;
infile ‘/home/wdigrazi/Desktop/MySAS/Data/grades.txt’; input Age Gender Midterm Quiz FinalExam;
if missing(age) then delete; if Age le 39 then do;
AgeGrp = ‘Younger Group’;
Grade = .4*Midterm + .6*FinalExam; end;
else if Age gt 39 then do;
AgeGrp = ‘Older Group’;
Grade = (Midterm + FinalExam)/2;
end; Run;
Title ‘Listing of Grades’; Proc print data=grades noobs;
var Age Gender Midterm Quiz FinalExam AgeGrp Grade; Run;

Looping: (Do Loop)
• Use an iterative DO loop to make a table of squares and square roots
Data table;
do n = 1 to 10;
Square = n*n;
SquareRoot = sqrt(n);
output;
end; Run;
Title “Table of Squares and Square Roots”; Proc print data=table noobs;
Run;

Looping: (Do While Loop)
• A DO WHILE loop iterates as long as the condition following WHILE is true. The WHILE condition is tested at the top of the loop. Thus, a DO WHILE loop block does not execute even once if the condition is false.
Data double;
Interest = .0375;
Total = 100;
do while (Total le 200);
Year + 1;
Total = Total + Interest*Total;
output;
end;
format Total dollar10.2;
Run;
Title “Output for Do While Loop Interest”; Proc print data=double noobs;
Run;

Do and Conditional
• You can use DO loops and Conditionals together. The RANUNI function returns a number that is generated from the uniform distribution on the interval (0,1) using a prime modulus multiplicative generator with modulus 231- 1 and multiplier 397204094 (Fishman and Moore 1982)a
Seed Values:
Random-number functions and CALL routines generate streams of pseudo-random numbers from an initial starting point, called a seed, that either the user or the computer clock supplies. A seed must be a nonnegative integer with a value less than 2^31-1 (or 2,147,483,647). If you use a positive seed, you can always replicate the stream of random numbers by using the same DATA step. If you use zero as the seed, the computer clock initializes the stream, and the stream of random numbers cannot be replicated.

Do and Conditional
• You can use DO loops and Conditionals together. The RANUNI function returns a number that is generated from the uniform distribution on the interval (0,1) using a prime modulus multiplicative generator with modulus 231- 1 and multiplier 397204094 (Fishman and Moore 1982)a

Pause

Using SAS With Data From Excel
• Move Excel file from laptop to BlueHive using SCP on MACs and Win-SCP on Windows

Using SAS With Data From Excel
• Move Excel file from laptop to BlueHive using SCP on MACs and Win-SCP on Windows
Drag and drop the SampleGrades.txt file from C:\temp to /gpfs/fs1/home/yournetid/Desktop/MySAS/Data
NOTE: The Excel workbook that you want to work with in SAS should be saved as a new Tab Delimited File before doing this file transfer. The file transferred should be the Tab Delimited file

Using SAS With Data From Excel • Quit the Win-SCP program

Using SAS With Data From Excel • In the Program Editor Window, goto File➔Import Data

Using SAS With Data From Excel • Select Tab Delimited File (*.txt) as the file type to import and click Next

Using SAS With Data From Excel • Click the browse button to find the Tab Delimited File

Using SAS With Data From Excel • Click the browse button to find the Tab Delimited File and then click OK

Using SAS With Data From Excel • Click the Next button

Using SAS With Data From Excel
• Select the library and SAS Dataset name you want to give the imported file, then click Next

Using SAS With Data From Excel
• Provide a SAS Program name for the code that will be automatically written to the SAS Program representing the import steps the wizard created, then click Finish

Using SAS With Data From Excel • Notice the Log Window indicates the import worked correctly

Using SAS With Data From Excel • Open the myimport.sas program to see the code that was generated

Using SAS With Data From Excel • The code can be rerun in the future to do the same exact steps

Using SAS With Data From Excel • The data looks perfect

PROC Logistic
• Viewing PROC Freq output is helpful before running a PROC Logistic

PROC Logistic
Run a PROC logistic
where the model has the response variable as admit

PROC Logistic
Run a PROC logistic
where the model has the response variable as admit

PROC Logistic
Run a PROC logistic
where the model has the response variable as admit

Reminder
The subject matter of these short lectures were built upon the wealth of information in the book:
Learning SAS by Example: A Programmer’s Guide, Ron Cody SAS Publishing, 2007
ISBN 978-1-59994-165-3
If you are interested in knowing more about how useful SAS can be in your data management efforts, then this book is definitely worth purchasing for your
further education. There is no better way to learn than through examples and doing.

Thank You
Stay Safe, Healthy & Motivated
Good Luck On The Remainder Of The Course

Pause

Homework Assignment #6 Last Video