Search a character expression for a string, specific character, or word:INDEX/INDEXC Functions

Choose appropriate INDEX function to find target strings, individual letters, or strings on word boundaries.

Note:
Sample 1 uses INDEX to search for the first occurrence of a 'word' anywhere in a string. If the string is not found, the result is zero.

Sample 2 uses INDEXC to locate the first occurence of any character specified in the excerpt. If no target is found, the result is zero.**

Sample 3 uses INDEXW to find the target excerpt in a string on a word boundary. If the word is not found, the result is zero.






RESULTS:

Sample 1: INDEX



Sample 2: INDEXC



Sample 3: INDEXW



source:www.support.sas.com

Comments

  1. Hi,
    Can you assist to define an unconsistancy of fields of the same record-type in a file?.

    Eg:
    BAR00000135640810090000092324694041460 0 IT/ TWD300TW TWD81AY TWD7094XT TWD IT 773309UM002 U

    BAR00000202640810010000132329619451769 1 IT/ 300TW 81TQ 20949XTTWD IT 77660

    BAR00000251640810010000162329619451945 2 IT/ 300TW 994US 6144XTTWD IT 77661

    BAR00000064640810020000042324694034435 3 IT/ TWD300TW TWD81AY TWD7057XT TWD IT 77330Z9X006 U

    BAR00000119640810090000082324694041450 4 IT/ TWD300TW TWD480MY TWD4150YQ TWD IT 77330AP6XM U

    BAR00000090640810030000062324694034493 5 USD350.00/ TWD11277 TWD81AY TWD497US TWD2821XT TWD14676 773302K6001 U

    BAR00000012640810010000012321848590612 5MYR 909.00/TWD 8490TWD 3610YQTWD 324YQTWD 561MYTWD 12985 79060AA

    BAR00000029640810070000022321848591014 1IT / TWD 5028YQTWD 324YQTWD 2086XTIT 7906NAA

    BAR00000103640810030000072324694034494 6 USD263.00/ TWD8474 TWD81AY TWD497US TWD2821XT TWD11873 773302K6001 U

    BAR00000151640810090000102324694041473 6 IT/ TWD300TW TWD81AY TWD7094XT TWD IT 773309UM002 U

    ReplyDelete
  2. Hi,
    I've declared the fields as per below but subsequent records are having different format layout:

    INFILE XPF;
    INPUT @1 IND1 $CHAR3.
    @20 UNIQ $CHAR8.
    @12 IND2 $CHAR2. @;
    IF IND1='BAR' THEN DO;
    IF IND2='64' THEN DO;
    INPUT @26 TKTNO $CHAR13.
    @26 PRIMTKT $CHAR15.
    @14 DTEISS $CHAR11.
    @54 CURRFAR $CHAR3.
    @57 AMTFARE $CHAR8.
    @65 CURTAX1 $CHAR3.
    @68 TAXAMT1 $CHAR6.
    @74 TAXCOD1 $CHAR2.
    @76 CURTAX2 $CHAR3.
    @79 TAXAMT2 $CHAR6.
    @85 TAXCOD2 $CHAR2.
    @87 CURTAX3 $CHAR3.
    @90 TAXAMT3 $CHAR6.
    @96 TAXCOD3 $CHAR2.
    @101 AMTTOTF $CHAR8.;
    RETAIN;

    ReplyDelete

Post a Comment

Popular posts from this blog

SAS Interview Questions and Answers: CDISC, SDTM and ADAM etc

Comparing Two Methods for Removing Formats and Informats in SAS: DATA Step vs. PROC DATASETS

Studyday calculation ( --DY Variable in SDTM)