Kylie
Kylie

Reputation: 21

In SAS, are assigned variables always set to missing before each iteration?

I am confused as to why this code works and I'm afraid that this is due to misunderstanding of how SAS processes datasets. I thought that the PDV is initialized to missing each iteration for variables created in an assignment statement, while all other variableare overwritten with each iteration. So, I expected Promotion to be missing with the second iteration because there is no RETAIN statement. When is a RETAIN statement needed and why is it not needed here?

DATA work.extended;
    SET Orion.Discount;
    WHERE Month(Start_Date)=7 OR Month(End_Date)=7;
    DROP Unit_Sales_Price;
    Promotion="Happy Holidays";
    Season="Winter";
    Output;
    Season="Summer";
    Output;
    RUN;

Here is a sample of the output:

Obs Product_ID Start_Date End_Date Discount Promotion Season
1 210100100038 01JUL2007 31JUL2007 60% Happy Holidays Winter
2 210100100038 01JUL2007 31JUL2007 60% Happy Holidays Summer
3 210200100010 01JUL2007 31JUL2007 60% Happy Holidays Winter
4 210200100010 01JUL2007 31JUL2007 60% Happy Holidays Summer

Thank you.

Upvotes: 2

Views: 55

Answers (1)

Joe
Joe

Reputation: 63424

You're incorrectly defining iteration. One iteration of the data step is not one output, but one time from data to run (or return, which run has implied). Output has no relation to data step iterations, other than the implied output when it is not included.

I suggest the data step debugger (such as here ) if you want to see this in action.

Upvotes: 4

Related Questions