Home Forums Main Forums SAS Forum Format: ??8. — what the hell is it doing?

  • Format: ??8. — what the hell is it doing?

     Justin updated 7 months, 1 week ago 1 Member · 1 Post
  • Justin

    February 7, 2021 at 5:32 pm

    Sometimes you may see other people use below weird formats to input data. What is it and what the hell is it doing?

    Y=input(X, ?8.);
    Y=input(X, ??8.);

    Calm down, buddy, let me explain it to you.

    The optional question mark (?) and double question mark (??) format modifiers suppress the printing of both the error messages and the input lines when invalid data values are read. The ? modifier suppresses the invalid data message. The ?? modifier also suppresses the invalid data message and, in addition, prevents the automatic variable _ERROR_ from being set to 1 when invalid data are read.

    Below is an example of using ?? to determine whether a variable contains non-numeric values or not:

    data _null_;
    x = '12345678';
    if (input(x, ?? 8.) eq .) then put ‘non-numeric’;
    else put 'numeric';

    Running SAS would return “Numeric” in the above example. If we used X=”123a5678”, SAS would return “Non-Numeric”. Note that the input format in the above example is “8.” So only the first 8 bytes of the character string are checked.

    Thus, X=123456789a would return “Numeric” as it would only be checking the first 8 bytes of the string.

Log in to reply.

Original Post
0 of 0 posts June 2018