I saw this sample online and I will like to know the importance of the '&' after the variable 'Location'. Initially, i thought it was used to keep the observation(cole pond, Eagle lake) in one column but I did removed it and still got the same output.
Thanks.
Sample code:
options nodate pageno=1 linesize=80 pagesize=40;
data fishdata;
infile datalines missover;
input Location & $10. Date date7.
Length1 Weight1 Length2 Weight2 Length3 Weight3
Length4 Weight4;
format date date7.;
datalines;
Cole Pond 2JUN95 31 .25 32 .3 32 .25 33 .3
Cole Pond 3JUL95 33 .32 34 .41 37 .48 32 .28
Cole Pond 4AUG95 29 .23 30 .25 34 .47 32 .3
Eagle Lake 2JUN95 32 .35 32 .25 33 .30
Eagle Lake 3JUL95 30 .20 36 .45
Eagle Lake 4AUG95 33 .30 33 .28 34 .42
; run;
The & modifier tells the INPUT statement that you need to have two delimiters in a row to mark the end of the next field. This will allow you to read values with embedded single delimiters.
The reason it didn't matter in your code is because you are using formatted input, so the INPUT statement does not need to try to figure out where the next field ends, it just reads the number of bytes you told it to read.
It is hard to tell what your data lines look like since you let this forum editor flow them into paragraphs. But if your data looks like this:
Cole Pond 2JUN95 31 .25 32 .3 32 .25 33 .3 Cole Pond 3JUL95 33 .32 34 .41 37 .48 32 .28 Cole Pond 4AUG95 29 .23 30 .25 34 .47 32 .3 Eagle Lake 2JUN95 32 .35 32 .25 33 .30 Eagle Lake 3JUL95 30 .20 36 .45 Eagle Lake 4AUG95 33 .30 33 .28 34 .42
Then your formatted more input is not going to work. The place where second field starts is NOT on the same place on every line.
The & is also not going to work. There are NOT two spaces after the end of the LOCATION value. PS Why the heck would anyone be using 2 digits for the year part of a date string?
You should edit the data. You could make it fixed column (at least for the first two fields).
Cole Pond 02JUN95 31 .25 32 .3 32 .25 33 .3 Cole Pond 03JUL95 33 .32 34 .41 37 .48 32 .28 Cole Pond 04AUG95 29 .23 30 .25 34 .47 32 .3 Eagle Lake 02JUN95 32 .35 32 .25 33 .30 Eagle Lake 03JUL95 30 .20 36 .45 Eagle Lake 04AUG95 33 .30 33 .28 34 .42
Then this mix of formatted and list mode input styles will work.
input Location $11. Date date7.
Length1 Weight1 Length2 Weight2 Length3 Weight3 Length4 Weight4
;
Or you could make sure there are at least two spaces after the first field.
Cole Pond 02JUN95 31 .25 32 .3 32 .25 33 .3 Cole Pond 03JUL95 33 .32 34 .41 37 .48 32 .28 Cole Pond 04AUG95 29 .23 30 .25 34 .47 32 .3 Eagle Lake 02JUN95 32 .35 32 .25 33 .30 Eagle Lake 03JUL95 30 .20 36 .45 Eagle Lake 04AUG95 33 .30 33 .28 34 .42
Then this list mode only input styles will work. Notice the : modifier which tells the INPUT statement to adjust the width of the informat to match the width of the next field on the line.
input Location &:$10. Date :date7.
Length1 Weight1 Length2 Weight2 Length3 Weight3 Length4 Weight4
;
If your current input is working with your current data (at least for the first field) then you might find it easiest to just add the colon modifier to the date informat so that four digit years or extra spaces don't cause any trouble.
input Location $10. Date :date.
Length1 Weight1 Length2 Weight2 Length3 Weight3 Length4 Weight4
;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.