Desktop productivity for business analysts and programmers

Loop failing only for a particular data set

Reply
Contributor
Posts: 51

Loop failing only for a particular data set


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;

PROC Star
Posts: 7,429

Re: Loop failing only for a particular data set

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

Contributor
Posts: 51

Re: Loop failing only for a particular data set

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

Respected Advisor
Posts: 4,803

Re: Loop failing only for a particular data set

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
Super User
Posts: 19,033

Re: Loop failing only for a particular data set

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.

PROC Star
Posts: 7,429

Re: Loop failing only for a particular data set

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.

Contributor
Posts: 51

Re: Loop failing only for a particular data set

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.


Super User
Posts: 19,033

Re: Loop failing only for a particular data set

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.

Contributor
Posts: 51

Re: Loop failing only for a particular data set

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.

Super User
Posts: 19,033

Re: Loop failing only for a particular data set

Post the full code/error/log.

Ask a Question
Discussion stats
  • 9 replies
  • 673 views
  • 6 likes
  • 4 in conversation