Post by palaparaHi there,
I think I have messed up the programming languages..
How to specify a var is null in SAS?
if id is null then id=lag(id);
is the above correct or should be something such as missing, etc...?
Thanks!
SAS doesn't use the term "null", and variables in SAS can't have null values
the way they do in, for instance, ORACLE. The closest thing in SAS to a
null value is a missing value.
To set a numeric variable to missing, use a period like this: a = .;
For character variables, missing values are spaces, so to set a character
variable to missing, do this: b = ' ';
But beware - unlike ORACLE, missing values compare in SAS - a missing value
is always the lowest possible value. If a and b are variables, and both are
missing values, then the condition IF A = B is true in SAS. In ORACLE, if
they're both null values, the condition is not true.
LAG: The LAG function does not return the value from the previous
observation, it return the value from the previous execution of the lag
function. In the statement you show in your post, the lag function would
execute only when ID was missing, so the only thing it could return is a
missing value.
Assuming ID is a numeric variable, I think what you want is something like
RETAIN HOLDID;
SET whatever;
IF ID ^= . THEN HOLDID = ID;
IF ID = . THEN ID = HOLDID;