Reading Character Values That Contain Blanks - SAS Programming

The key property of list input is that at least one blank space separates each data value from the next.But what if the data value contains blanks, like a first and last name combination,or a multi-word city name like New York? All is not lost.With a little help,a SAS INPUT statement can read data values that contain one or more single blanks.You do this by following the variable name that contains the blank spaces with the ampersand (&) format modifier.You can then also use an informat if you wish, as you did with the colon modifier.

The rule now is that there must nbe at least two consecutive blank spaces separating data values. So, in order to read data containing a 25-byte character variable NAME,which could be made up of multiple words,use the following code:

Example

DATA AMPERS;
INPUT NAME & $25. AGE GENDER : $1.;
DATALINES;
RASPUTIN 45 M
BETSY ROSS 62 F
ROBERT LOUIS STEVENSON 75 M
;
PROC PRINT DATA=AMPERS;
TITLE 'Example 4';
RUN;

Notice that there are at least two spaces after each complete name.In fact, there are four spaces after RASPUTIN.The output for this example follows:

Output from Example - Reading Character Values That Contain Blanks

Output from Example  - Reading Character Values That Contain Blanks


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics