useR
useR

Reputation: 3082

Retain leading blank when reading raw data using datalines method

According to below output, the leading to trimmed automatically for the fourth observations. cdefg -> cdefg.

Question: How can i retain the leading blank.

data chr2;
    input string $ 1-25;
    strLen = length(string);
    compblStr = compbl(string);
    compblLen = length(compblStr);
    datalines;
abc 5678
abcd  78
 bcdef 8
  cdefg  
;
run;

Upvotes: 2

Views: 626

Answers (1)

Vasilij Nevlev
Vasilij Nevlev

Reputation: 1449

You need to use $charW. informat to keep training blanks. This informat preserves leading and trailing blanks.

data chr2;
    input string $CHAR25.;
    strLen = length(string);
    compblStr = compbl(string);
    compblLen = length(compblStr);
    datalines;
abc 5678
abcd  78
 bcdef 8
  cdefg  
;

Upvotes: 4

Related Questions