The below loop fails only for wk 51 & wk 52 data for FY14 Q4. The loop works fine for all other time periods. Please advise what could be the reason
SELECT (REGION);
WHEN ('Americas')
DO;
IF IP_DATE = . OR DLVR_STRT_DTS = . THEN DO;
SDS_EXP_IP = 'N/A';
SDS_GRD_IP = 'N/A';
SDS_ALL_IP = 'N/A';
END;
ELSE DO;
IF DATEPART(IP_DATE) = DATEPART(DLVR_STRT_DTS) THEN SDS_ALL_IP = 'MADE';
ELSE SDS_ALL_IP = 'MISS';
IF SHIP_CD IN ('2','7') THEN DO;
SDS_GRD_IP = 'N/A';
IF DATEPART(IP_DATE) = DATEPART(DLVR_STRT_DTS) AND
TIMEPART(DLVR_STRT_DTS) LE "19:00"T THEN SDS_EXP_IP = 'MADE';
ELSE SDS_EXP_IP = 'MISS';
END;
ELSE DO;
SDS_EXP_IP = 'N/A';
SDS_GRD_IP = SDS_ALL_IP;
END;
END;
END;
WHEN ('EMEA','APJ')
DO;
SDS_EXP_IP = 'N/A';
SDS_GRD_IP = 'N/A';
IF DATEPART(IP_DATE) = DATEPART(DLVR_STRT_DTS) THEN SDS_ALL_IP = 'MADE';
ELSE SDS_ALL_IP = 'MISS';
END;
END;
END;
END;
Your error is probably coming from somewhere else in your data step.
as per the line number in the error message it states that When clause is not satisfied even though there's data for EMEA & APJ
I think the message warns you about the fact that you've got some data where REGION is not "Americas" or "AMEA" or "APJ". Add an OTHERWISE clause to your SELECT block to detect those.
PG
SAS will tell you that one
ERROR: Unsatisfied WHEN clause and no OTHERWISE clause at line 552 column 1.
And you can use a list in your When Clause.
Fareeza: I deleted my post about not being able to use a list. I tested it, after posting, and then went back and deleted my post.
The issue has been resolved by using the otherwise clause. IT appears the format for region name had changed for specific weeks causing the loop to fail.
Thank you so much for each one of you for the guidance.
I'd check if the DO/END matched. The way you have the code right now (indent!), I'm not about to figure it out.
The full code/error/log is also useful if you're trying to debug something.
everything is matched for other time period data extractions. When i try to extract data for a specific period then i am getting the error. If i do the extraction for a week prior it works and the same goes for a week later from the specific period. Please advise.
Post the full code/error/log.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.