I have the following three data steps, each of which reads in two variables from the embedded raw data. The two variables are separated by THREE spaces in all cases. See SAS code below:
data Char;
input name $ +2 income comma5.;
datalines;
Tom 1,098
;
run;
data Num;
input id +2 income comma5.;
datalines;
123 1,098
;
run;
data Informat;
input balance comma5. +3 income comma5.;
datalines;
5,123 1,098
;
run;
As you can see, for the char and numeric variables, I need to do a +2 on the input pointer for the following informat to work; however, if the first variable uses an informat, it needs a +3 on the pointer. Can someone please explain this difference of pointer position?
The main difference is that the cursor is positioned differently when you read a value in LIST MODE than when you read it in FORMATTED MODE. With FORMATTED MODE then an exact number of bytes are read. With LIST MODE then next "word" on the line is read.
If you want to specify an informat in-line in the INPUT statement and still use LIST MODE input then add the colon modifier before the informat. When reading in list mode the width of the informat is ignored, the whole next "word" on the line is read. So no need to add the 5 width to the COMMA informat specification.
data want;
input name $ income :comma.;
datalines;
Tom 1,098
;
The main difference is that the cursor is positioned differently when you read a value in LIST MODE than when you read it in FORMATTED MODE. With FORMATTED MODE then an exact number of bytes are read. With LIST MODE then next "word" on the line is read.
If you want to specify an informat in-line in the INPUT statement and still use LIST MODE input then add the colon modifier before the informat. When reading in list mode the width of the informat is ignored, the whole next "word" on the line is read. So no need to add the 5 width to the COMMA informat specification.
data want;
input name $ income :comma.;
datalines;
Tom 1,098
;
If you want to see how the pointing is positioned use the COLUMN= infile option.
17 data Char; 18 infile datalines column=col ; 19 input name $ @; 20 put col=; 21 input +2 income comma5.; 22 datalines; col=5 NOTE: The data set WORK.CHAR has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.03 seconds cpu time 0.00 seconds 24 ; 25 26 data Num; 27 infile datalines column=col ; 28 input id @; 29 put col=; 30 input +2 income comma5.; 31 datalines; col=5 NOTE: The data set WORK.NUM has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 33 ; 34 35 data Informat; 36 infile datalines column=col ; 37 input balance comma5. @; 38 put col=; 39 input +3 income comma5.; 40 datalines; col=6 NOTE: The data set WORK.INFORMAT has 1 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.