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

MET MA 603: SAS Programming and Applications

MET MA 603:
SAS Programming and Applications

Automatic Variables

1

1

In a Data step, SAS creates several variables that it uses in processing the step. Automatic Variables are temporary variables created during each Data step and used by SAS in processing.
Automatic variables do not get written to the output dataset. However, sometimes it is useful to reference them in the Data step.
The automatic variables that will be covered are:
_N_
First.var
Last.var.
Automatic Variables

2

2

The automatic variables First.var and Last.var indicate, with a 1 or 0, whether the current observation is the first or last occurrence, respectively, of the variable var.
The First. and Last. automatic variables are only created when the BY statement is used, and the input dataset must be sorted according to the way the variables appear in the BY statement.
First. and Last.

3

3

The automatic variable _N_ indicates the number of times SAS has looped through a Data step.
Recall that when SAS processes a Data step there is a built-in loop, where each statement is executed for each observation. Each time SAS loops through the statements in the Data step, the automatic variable _N_ is incremented by 1.
Usually _N_ can be thought of as the row number of each observation. This is true for simple Data steps, where the number of observations in the input and output datasets are the same.

_N_

4

4

Practice
From the losses.sas7bdat dataset, create a new dataset that contains the 5 biggest losses from 2014

5

5

Practice
From the losses.sas7bdat dataset, create a new dataset that contains a random sample of 5 losses from 2014 where the loss amount is greater than 9,999. (Your sample will likely differ from what is below, and you should get a different result each time you run your code).
Use the random number function RAND(“Uniform”) to generate random numbers.

6

6

Readings

Textbook section 6.15

7

7

/docProps/thumbnail.jpeg