Using a RETAIN Statement to Initialize Constants - SAS Programming

If you write a DATA step in which you assign values to certain constants, you can either do the assignment work for each and every observation, or you can do it just once by using a RETAIN statement. Which do you suppose we recommend? Here is the inefficient method:

Example– INEFFICIENT

DATA TEST;
INFILE 'file_specification';
A = .10; ~
B =1.57;
PI=3.14159;
INPUT X @@;
Y=A*X+B*PI*X;
DROP A B PI;
RUN;

In this code, the values for A, B, and PI are assigned at every iteration of the data set.You really only have to do it once and then merely RETAIN the values for all succeeding observations.It looks like this:

Example – EFFICIENT

DATA TEST;
INPILE 'file_specification';
RETAIN A .10
B 1.57
PI 3.14159;
INPUT X @@;
Y=A*X+B*PI*X;
DROP A B PI;
RUN;

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics