I know why because I kept the first condition as not correct. I have changed it. I was tired last night and could not spot it (neither the error nor the fact that the excel file you sent had approximately 1460 rows. SAS Studio just outputs 100 rows at a time, by default. So I am sorry about all that. Here is the code. DATA Temp_Processed;
SET Temp;/*Change as per your data name*/
RETAIN Year_Flag 0;
RETAIN Frost 0;
IF Year_Flag ^=0 and DAY > 180 and Temp < 2 THEN
OUTPUT;
ELSE IF DAY > 180 and Temp < 2 and Year_Flag=0 THEN
DO;
Frost=1;
Year_Flag=Year;
OUTPUT;
END;
ELSE IF DAY <=180 THEN
DO;
Frost=0;
Year_Flag=0;
OUTPUT;
END;
RUN; You can confirm that for the intended Frost range, it is correctly assigned ... by doing a simple PROC SQL. PROC SQL;
SELECT
MIN(DAY) AS StartingDate,
MAX(DAY) AS EndDate,
Year_Flag,
Frost
FROM
Temp_Processed
GROUP BY
Year_Flag,
Frost;
QUIT; It outputs the intended result. Sorry again for creating a confusion. Fortunately you got a solution that was working for you and thus your time was not lost by my solution.
... View more