程序代写代做代考 MET MA 603: SAS Programming and Applications

MET MA 603: SAS Programming and Applications

MET MA 603:
SAS Programming and Applications

Data Steps and Procedures

1

1

Data Steps
A Data Step is a special block of code for reading and modifying datasets.
Example of a Data Step:
data distance ;
Miles = 26.22 ;
Kilometers = 1.61 * Miles ;
run ;
This Data Step contains four statements.
This Data Step creates an output dataset called “distance” which has one observation and two variables, “Miles” and “Kilometers”.
In this example there is no input dataset.

2

2

Data statement
The Data statement instructs SAS to initiate a Data Step.
The keyword Data can be followed by the name of a dataset to be created, _NULL_ (which instructs SAS to not create a dataset), or nothing at all (which instructs SAS to use a default name for the dataset).
data distance ; creates a dataset named “distance”
data ; creates a dataset with a default name
data _null_ ; does not create a dataset
The statements that follow the Data statement are executed when SAS encounters one of the keywords Run, Data, or Proc.

3

3

Procedures
A Procedure is a special block of code for analyzing datasets and producing reports. Procedures are designed to accomplish a specific task, and usually require entering a specific sequence of code.
Procedures usually require specifying input and output datasets, and may include additional optional or required statements or arguments.
Example of a Procedure:
Proc Print data = distance ;
run ;

4

4

The Print Procedure
The Print Procedure displays an input dataset in the Results Window. This particular Procedure doesn’t have an output dataset.
In the example below, “distance” is the input dataset.
Example of the Print Procedure:
Proc Print data = distance ;
run ;
“Noobs” is an optional argument that can be used with Proc Print, that will suppress the printing of the observation number.
Example of the Print Procedure with the noobs argument included:
Proc Print data = distance noobs ;
run ;

5

5

Run statement
The Run statement instructs SAS to run the statements that precede it.
SAS recognizes the end of a Data Step or Procedure when it encounters either a Data Step, a Procedure, or a Run statement.
Example with optional Run statement:
Data distance ;
Miles = 26.22 ;
Kilometers = 1.61 * Miles ;
Proc Print data = distance ;
run ;
SAS recognizes the end of the Data Step when it encounters the keyword Proc. SAS recognizes the end of the Procedure when it encounters the Run statement.

6

6

Practice
Debug the code below:
Datas temperature ;
Fahrenheit = Celsius * 9 / 5 + 32 ;
Celsius = 25
Kelvin = Celsius + 273.15 ;
Rankine = Farhenheit + 459.67 ;
Print data = temperatures ; noobs ;

Once the code has been fixed and executed, how many observations are in the resulting dataset? How many variables?

7

7

Readings

Textbook sections 1.3, 1.8, 1.9

8

8

/docProps/thumbnail.jpeg