Contributor
Posts: 60

# What do these numbers mean in the input statement?

Hi Forum,

Sorry I know the Subject isn't very clear but it's the best I can do.

I've seen these numbers from 'x' to 'y', but haven't seen a clear explanation of what they are for?

I got this code from the Step-by-Step Programming with
Base SAS® Software guide.

data club2;
input #2 Team \$ 1-6 #1 Name \$ 6-23 IdNumber 1-4
#3 StartWeight 1-3 EndWeight 5-7;
datalines;
1023 David Shaw
red
189 165
1049 Amelia Serrano
yellow
145 124
;

Can someone tell me what do the '1-6', '6-23' etc numbers mean & what function do they perform?

Thanks

Regular Contributor
Posts: 195

## Re: What do these numbers mean in the input statement?

Look at the documentation of the input statement.
Contributor
Posts: 60

## Re: What do these numbers mean in the input statement?

I have & then posted this question

Posts: 1,826

## Re: What do these numbers mean in the input statement?

input #2 Team \$ 1-6
#1 Name \$ 6-23 IdNumber 1-4
#3 StartWeight 1-3 EndWeight 5-7;

means that your data is spread on 3 input rows: #1 #2 #3.

I would prefer read rows in proper order: #1 first, then #2 and last #3.

the \$ sign means to read a character type data, e.g the NAME is from position 6 to position 23.

IDNUMBER is numeric 4 digits from position 1.

Contributor
Posts: 24

## Re: What do these numbers mean in the input statement?

hi

these numbers  after the variable names in input statement describes -from which position   and to which position should this variable read that data from datalines.

# 2  team \$ 1-6  describes that data from second line(#2)  in datalines read from position 1 to 6 as team.

and so on..

Contributor
Posts: 60

## Re: What do these numbers mean in the input statement?

Thanks RM6,

I think I get it but wouldn't this mean you would need to know the minimum & maximum length of the fields in order to write the correct range?

Is this used for alignment of data when presented?

I'm not getting why it's required/used?

Thanks

Contributor
Posts: 24

## Re: What do these numbers mean in the input statement?

well usually you should have a data dictionary of some sort which gives you these start position and end position.

as you are trying to read data from multiple lines in to single line of data in to your dataset, it is pretty important to know what data goes to which variable.
Contributor
Posts: 60

## Re: What do these numbers mean in the input statement?

Thanks RM6,

I wasn't aware that I needed a DD to find this out.

So is the purpose of these numbers for SAS to know when to add a new record (Row) using the values after the 'Datalines' statement?

Posts: 1,826

## Re: What do these numbers mean in the input statement?

[ Edited ]

There are, at least, to types of input data:

1) Fixed length where each variable has its start position and end position the same along all input rows

2) Variable length where except the first one all other may have different stsrt position and different length.

In subh case you need define a chracter to serve as delimiter between the variables.

See option delimiter= (or dlm=) and dsd in the input statement documentation.

In CSV files the comma is rthe delimiter brtween variables.

Super User
Posts: 6,543

## Re: What do these numbers mean in the input statement?

I don't think I'm adding anything new, just saying the same thing using different words.

The INPUT statement is your instructions on how to read lines of incoming data.  So 1-6 says take the contents of columns 1 through 6, and make that the value of TEAM.  Similarly, take the contents of columns 6 through 23, and make that the value of NAME.

Surely the documentation has examples of this.  Perhaps those examples are not complicated by the use of #.

Contributor
Posts: 60

## Re: What do these numbers mean in the input statement?

Thanks Schmuel, RM6 & Astounding,

What if I ask the question "What happens if I don't use these numbers in my Input statement?

Thanks

Contributor
Posts: 24

## Re: What do these numbers mean in the input statement?

well you will not get the desired output you are looking for, if you remove the numbers. In your example you are trying to read name as "David Shaw" , lets say you want to remove the start and the end position then name will read only "David" as there is a space in between the Name variable can not read entire "David Shaw".

if you have trouble finding the end position for the variables, or each time you receive a new data file end position changes

try this, in the below sample, you don't have to define the end position but you will atleast need the start position .

data club2;

input #2 @1 Team \$

#1 @6 Name \$30.

@1 IdNumber

#3 @1 StartWeight

@5 EndWeight ;

datalines;

1023 David Shaw

red

189 165

1049 Amelia Serrano

yellow

145 124

;

run;

Super User
Posts: 7,860

## Re: What do these numbers mean in the input statement?

Make sure to post code using either Insert Code or Insert SAS Code buttons in the editor. Otherwise the forum software will try to turn you code into paragraphs.  This will mess up the formatting, which is critical if you are trying to read data by position.

If you are looking at your data file using a text editor make sure to use a fixed space font (like COURIER) so that the character positions line up.

If you are using the SAS program editor (under display Manager) you can ask it to insert a ruler line to make it easier to see the positions.

You can also use a data step with the LIST statement to dump some lines to the SAS log.  For example this data step will dump the first 10 lines of the file referenced to the log.

data _null_;
infile 'mytextfile' obs=10;
input;
list;
run;
Discussion stats
• 12 replies
• 254 views
• 1 like
• 6 in conversation