Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading a period as character value in SAS

Tags:

sas

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.

like image 436
athresh Avatar asked Oct 04 '13 07:10

athresh


People also ask

How do you read a character variable in SAS?

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.

How do I find the value of a variable in SAS?

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.


1 Answers

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.

like image 155
vasja Avatar answered Oct 04 '22 15:10

vasja