data abc;
input stud $35. Age;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
run;
You told it to read the first 35 bytes into the first variable.
You can use the LIST statement
data _null_;
input ;
list;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
to see a nice listing that shows why that cannot work for the data you posted.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 675 animesh mardi 25 676 nahir sharma 26 677 agent rank 22 678 niharika ghatgey 23 679 pushpanjali kujur 22 NOTE: DATA statement used (Total process time):
If you want your code to work the data need to look like this:
*---+----1----+----2----+----3----+----4-;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
You could add the : modifier to the input statement so that it only uses the informat to GUESS what length you wanted to define the variable. But you would still need to also add the & modifier and change the data to have two spaces after the string (and not have two spaces embedded in the string).
data abc;
input stud & :$35. Age;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
You could also change the data to use something other than space are the delimiter and add an INFILE statement to tell SAS to use that delimiter.
data abc;
infile cards dlm='|';
input stud :$35. Age;
cards;
animesh mardi|25
nahir sharma|26
agent rank|22
niharika ghatgey|23
pushpanjali kujur|22
;
When you use formatted INPUT, you have to provide enough characters in the data before the next column.
All stud entries must be 35 characters long (pad with blanks).
Or you use an INFILE statement with the DSD option, quotes around the stud values, and the colon modifier for the $35. informat.
data abc;
infile datalines dsd;
input stud :$35. Age;
cards;
"animesh mardi" 25
;
One thing you need to be aware of with this forum. The forum software will reformat text pasted into the main message window. So it is possible that the data step you pasted is not what we actually see. You should post code, especially data step code reading inline data, into a text box opened on the forum using the </> icon that appears above the main message window.
It will then appear set off as in @Kurt_Bremser 's post.
You told it to read the first 35 bytes into the first variable.
You can use the LIST statement
data _null_;
input ;
list;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
to see a nice listing that shows why that cannot work for the data you posted.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0 675 animesh mardi 25 676 nahir sharma 26 677 agent rank 22 678 niharika ghatgey 23 679 pushpanjali kujur 22 NOTE: DATA statement used (Total process time):
If you want your code to work the data need to look like this:
*---+----1----+----2----+----3----+----4-;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
You could add the : modifier to the input statement so that it only uses the informat to GUESS what length you wanted to define the variable. But you would still need to also add the & modifier and change the data to have two spaces after the string (and not have two spaces embedded in the string).
data abc;
input stud & :$35. Age;
cards;
animesh mardi 25
nahir sharma 26
agent rank 22
niharika ghatgey 23
pushpanjali kujur 22
;
You could also change the data to use something other than space are the delimiter and add an INFILE statement to tell SAS to use that delimiter.
data abc;
infile cards dlm='|';
input stud :$35. Age;
cards;
animesh mardi|25
nahir sharma|26
agent rank|22
niharika ghatgey|23
pushpanjali kujur|22
;
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.