BookmarkSubscribeRSS Feed
sharath_rk
Calcite | Level 5


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;

9 REPLIES 9
art297
Opal | Level 21

Your error is probably coming from somewhere else in your data step.

sharath_rk
Calcite | Level 5

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

PGStats
Opal | Level 21

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

PG
Reeza
Super User

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.

art297
Opal | Level 21

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.

sharath_rk
Calcite | Level 5

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.


Reeza
Super User

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.

sharath_rk
Calcite | Level 5

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.

Reeza
Super User

Post the full code/error/log.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2959 views
  • 6 likes
  • 4 in conversation