7

I am reading a period '.' as a character variable's value but it is reading it as a blank value.

data output1;
input @1 a $1. @2 b $1.  @3 c $1.;
datalines;
!..
1.3
;
run;

Output       Required
------       --------
A  B  C      A  B  C
!            !  .  .
1     3      1  .  3

Please help me in reading a period as such.

athresh
  • 553
  • 6
  • 11
  • 24

2 Answers2

12

The output is determined by the informat used ($w. informat in your case, requested by $1. in your code, so $1. is first of all informat definition, lenght definition of variable is a side product of this).

Use $char. informat for desired result.

data output1;
input @1 a $char1. @2 b $char1.  @3 c $char1.;
datalines;
!..
1.3
;
run;

From documentation:

$w Informat The $w. informat trims leading blanks and left aligns the values before storing the text. In addition, if a field contains only blanks and a single period, $w. converts the period to a blank because it interprets the period as a missing value. The $w. informat treats two or more periods in a field as character data.

$CHARw. informat The $CHARw. informat does not trim leading and trailing blanks or convert a single period in the input data field to a blank before storing values.

vasja
  • 4,732
  • 13
  • 15
0

I don't immediately see why it does not work. But if you are not interested in figuring out why it does not work, but just want something that does: read it in as 1 variable of length $3. Then in a next step; split it using substr.

E.g.,

data output1;
    length tmp $3;
    input tmp;
    datalines;
        !..
        1.3
    ;
run;
data output2 (drop=tmp);
    length a $1;
    length b $1;
    length c $1;

    set output1;

    a=substr(tmp,1,1);
    b=substr(tmp,2,1);
    c=substr(tmp,3,1);
run;
mvherweg
  • 1,272
  • 9
  • 11