Reading a period as a character value in SAS

I read the period. "As the value of a character variable, but it reads it as an empty value.

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

Please help me in reading the period as such.

+6
source share
2 answers

The output is determined using the informat used ($ w. Informat in your case, requested $1. In your code, so $1. Is, first of all, the definition of an informant, the definition of the length of a variable is a byproduct of this).

Use $ char. informat for the desired result.

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

From the documentation:

$ w Informat $ W. informat aligns leading spaces and aligns the values ​​to the left before saving text. Also, if the field contains only spaces and one period, $ w. converts a period to empty because he interprets this period as a missing value. $ W. informat treats two or more periods in a field as character data.

$ CHARw. inform $ CHARw. informat does not trim leading and trailing spaces or does not convert one period in the input data field to a space before storing values.

+11
source

I do not immediately understand why this does not work. But if you are not interested in finding out why this does not work, you just need to do something: read it as 1 variable with a length of $ 3. Then in the next step; separate it with substr.

eg.

 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; 
0
source

Source: https://habr.com/ru/post/955233/


All Articles