10-07-2016 11:03 AM - edited 10-10-2016 08:58 AM
data uspop; input pop :6.3 @@; retain year 1780; year=year+10; label pop='U.S. Population in Millions'; datalines; 3929 5308 7239 9638 12866 17069 23191 31443 39818 50155 62947 75994 91972 105710 122775 131669 151325 179323 203211 226542 248710 ;
Who can tell me what the mean of "input pop:6.3 @@" is?
I know that "@@" means to repeat read in the data but I cannot understand why there is a semicolon between pop and 6.3 and I have tried to look up it in instruction but I still cannot understand it.
10-07-2016 11:11 AM
The : on an input that way says to use the following format to read the values. In this case the 6.3 says that the longest value will be 6 charcters and to insert a decimal prior to the last the 3 numerals.
It is documented in the INPUT statement syntax reference.
10-07-2016 11:16 AM - edited 10-07-2016 11:25 AM
The colon basically tells SAS that if it encounters a space it should stop reading data for that observation and start again the next time it encounters a non-blank space. It is useful where you are reading in data that has a variety of lengths for a single variable and a somewhat inconsistent way of storing the data (i.e. in your example you have lengths ranging from 4 numbers to 6, with an inconsistent number of blank spaces from one record to another).
If you run your code without the colon you will notice that after the 5th observation (12.866) your table starts to have problems with the data, the reason being that SAS will read 6 numbers - regarless of whether or not it encounters blank space and will format the number it reads in those 6 numbers into 3 decimal places. You can see that the 6th observation is 1.706 - because SAS has read in
'. . 1 7 0 6 ' (where the . is a blank space) for this observation.
Hope this helps
10-07-2016 11:51 AM
Here the docu link:
Just run the code without a colon and see what happens (as explained by @BenbowL).
10-07-2016 12:32 PM - edited 10-07-2016 12:36 PM
The : modifier tells SAS to use the next "word" for input. So rather than reading exactly the 6 characters that are specified by informat it reads as many characters as it sees for the next word. Since you did not request otherwise it is uses spaces to delimit the words and it will treat multiple spaces as one. The other thing that using the : modified does is that SAS will ignore the length specified on the informat and instead use the actual length of the word. That doesn't matter in your example since the longest word is 6 digits, but you could change the informat from 6.3 to 5.3 or 32.3 and it would still read the data the same way if you are using the : modifier.
Also note that by specifing a decimal part in the informat you are telling SAS that if the word does not already have a decimal point then assume there is one before the third from last digit. So basically divide the value by 1,000. If any of your words did have a decimal point then it would just read the value and not move the decimal point.
You can see the effect of the : modifier on where SAS is leaving the pointer by looking at the COLUMN= option on the INFILE statement. Try running this program and look at the log.
data uspop; infile cards col=loc; put loc= @; input pop :3.3 @@; list; retain year 1780; year=year+10; label pop='U.S. Population in Millions'; put year= pop= loc= ; cards; 3929 5308 7239 9638 12866 17069 23191 31443 39818 50155 62947 75994 91972 105710 122775 131669 151325 179323 203211 226542 248710 ;