Hello team,
I have input statement:
input name $16. age 3. +1 type $1. +1
I wonder what we have dots for and what the functionality of +1 is.
This is from "The little SAS Book".
When name is $16 characters, It pulls following characters to the variable "name". How to take care of this task? Names might have 8, 10 or variety of characters.
data contests;
Input....;
datalines;
....
...
;
Run;
Regards,
Blue Blue
Format and Informat names require the dot so SAS knows that is the purpose of the syntax element.
The +1 (or other number or even a variable) is a column pointer movement. It tells SAS to start "one more column to the right" then the current position of the input (or output ) pointer in the text.
In the example
input name $16. age 3. +1 type $1. +1
reading name and age would use 19 columns of the input file. The +1 says to skip column 20 and start reading at column 21. The informats specified expect the data to start in specific positions and have specific lengths of characters to read.
Combinations of options to read data is very dependent on the actual text.
The exact data you want to read depends on what you have for text. If the value, such as name may have spaces in the middle, such as "John Smith" then you need to use a technique to read across the blank. Some files will have a delimter, such as comma between values and you tell SAS that is the case with an INFILE statement and the DLM=',' option.
If your data does not have a space in the middle you can use a : before the format name which means "start at the next non-blank and read what is there using the format specified". If the actual length of the value is longer than 16 characters the next read will start in the middle of the work.
You should provide example of the raw text to read in a text box opened on the forum with the </> because the message windows will reformat text and often remove "extra" spaces.
You should also provide what you expect the result to be.
data example; /* this is called Formatted input, the format controls how much of the text to read the AGE value cannot start before column 17
else it is treated as part of the name. The entire age would have
to be columns 17 to 19 (3 columns) */ input name $16. age 3. +1 type $1. ; /*< that last +1 does nothing if there isn't another variable to read*/ datalines; John Smith 23 A ; data example2; /*delimited input*/ infile datalines dlm=','; input name :$16. age :3. type :$1. ; datalines; John Smith,23,A ; data example3; /*simple list input doesn't read spaces imbedded in words*/ input name :$16. age :3. type :$1. ; datalines; JohnSmith 23 A ;
Sometimes you have to modify the file. Sometimes spend some time parsing the data.
Hello,
Thank you very much for your input.
Still, it doesn't take the variables properly in. I don't know why.
Allicia Grossman 12 a 2.2 3.3 4.4 5.5 6.6 ;
Please try this.
You see how all variables are not in proper columns.
Regards,
Blue Blue
@GN0001 wrote:
Hello,
Thank you very much for your input.
Still, it doesn't take the variables properly in. I don't know why.
Allicia Grossman 12 a 2.2 3.3 4.4 5.5 6.6 ;Please try this.
You see how all variables are not in proper columns.
Regards,
Blue Blue
What is the question?
If you know how the text file is structured then write the INPUT statement that reads the data in that structure.
It is hard to see any pattern in a sample of size one.
Here is how I would guess to read such a line.
data want;
input (name1 name2) (:$20.) v1 v2 $ v3-v7 ;
cards;
Allicia Grossman 12 a 2.2 3.3 4.4 5.5 6.6
;
@GN0001 wrote:
Hello,
Thank you very much for your input.
Still, it doesn't take the variables properly in. I don't know why.
Allicia Grossman 12 a 2.2 3.3 4.4 5.5 6.6 ;Please try this.
You see how all variables are not in proper columns.
Regards,
Blue Blue
You have to show us what you expect the result to be probably for more than one record at a time.
You should also show what result you are getting.
And the hint about posting text in text box really is important if we need to read text because the message windows do reformat stuff.
Basically you likely do not have the second variable aligned to read the data with the input statement, which you didn't show.
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.