10-02-2012 09:13 AM
I have a data set with 80 rows. For every set of 4 rows, I want to insert one kind of value into the first three rows, and a different value into the fourth row. I first figured the code might be something like this:
while not last row;
if _n_ <= 3 then do;
new_row = value1;
else if _n_ = 4 then do;
new_row = value2;
_n_ = 1;
I just realized I'm misusing _n_ though, and need to reconsider it. Perhaps I can use a custom count variable. In any case, my question is, how do I do the "while not last row" part of the code correctly? Actually, the last row should preferably be included.
Thanks for your attention.
10-02-2012 09:37 AM
Why not use the MOD function to test if you are on the 4th observation?
That way you can adjust the value of the new variable you are creating.
Note that normally new variables as referred to as columns instead of rows. If you actually meant to create new observations (aka new rows) then the code will be different, but the logic for finding every fourth observation would be the same.
if 0=mod(_n_,4) then new_variable=value2;