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.
after "Name" in INPUT statement. It changes the order of variables as the variable Name would be read first. We can use ampersand (&) to tell SAS to read the variable until there are two or more spaces as a delimeter. This technique is very useful when the variable contains two or more words.
For SAS programmers, the PUT statement in the DATA step and the %PUT macro statement are useful statements that enable you to display the values of variables and macro variables, respectively. By default, the output appears in the SAS log.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With