Monday, November 4, 2013

LINE POINTER CONTROL

What is Line Pointer Control?
Definition: It is technique by which SAS allows you to rearrange variables in a data set while reading data from raw data files. It lets you read multiple records either sequentially or non-sequentially and create single observation. It involves correct use of special characters like #n or / which are respectively called non-sequential and sequential (forward slash) line pointer controls.

What is advantage of Forward Slash Line Pointer Control?

When you are interested in creating one observation from multiple records without using multiple INPUT statements, forward slash line pointer control comes in handy.

ROMA TOMATO
FRESHPOINT CA
1.80 DAILY
GREEN BEANS
ORGANICS NC
1.20 WEEKLY

Code to read data file:

data produce.vegetables;
     infile vegdata;
     input VName $ 1-11 /
           Supplier $ State $ /
           Rate 4. Frequency $;
run;

This will create data set vegetables:


VName
Supplier
State
Rate
Frequency
ROMA TOMATO
FRESHPOINT
CA
1.8
DAILY
GREEN BEANS
ORGANICS
NC
1.2
WEEKLY

What is advantage of #n Line Pointer Control?

In case of accessing variables non-sequentially #n line pointer control comes in very handy. In the above example, if you were required to create data set with specific order of variables such as 

  1. Supplier
  2. State
  3. Rate
  4. Frequency
  5. VName

Then the best way to proceed is with use of #n as it allows you to jump on n record and go back and forth between multiple records to create one observation.

data produce.vegetables;
     infile vegdata;
     input #2 Supplier $ State $
           #3 Rate 4. Frequency $
           #1 VName;
run;

Data set created:


Supplier
State
Rate
Frequency
VName
FRESHPOINT
CA
1.8
DAILY
ROMA TOMATO
ORGANICS
NC
1.2
WEEKLY
GREEN BEANS

It is possible to control / Forward Slash and #n line pointer controls for more complex data records.


*** For questions and discussion, use COMMENTS section or email sasavant9.4@gmail.com























No comments:

Post a Comment