BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cosmid
Lapis Lazuli | Level 10

Noob question. I was reading a document from SAS support about List Inputs. The example given below is from their website. My question is why the pointer is located in column 5 and not column 4 after the value red is read?

 

data scores;

   input Team $ Score;

datalines;

red                59

blue              95

yellow           63

green            76

;

 

 

The following figure shows that the pointer is located in column 5 after the value red is read. Because Score, the next variable, is read with list input, the pointer scans for the next nonblank space before it begins to read a value for Score. Unlike column and formatted input, you do not have to explicitly move the pointer to the beginning of the next field in list input.

Pointer Position: List Input

[Pointer Position: List Input]

 

Link of original document, the above is at the very bottom of the page:

 

http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a002645710.htm

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

With LIST input, SAS has to read across the line until it finds a blank.  That's how it knows it has found all the characters.  So to find "red" as the value, SAS has to read the blank in column 4.  That's how it knows it has found all the nonblank characters, and it's why the pointer is now at column 5.

View solution in original post

7 REPLIES 7
Astounding
PROC Star

With LIST input, SAS has to read across the line until it finds a blank.  That's how it knows it has found all the characters.  So to find "red" as the value, SAS has to read the blank in column 4.  That's how it knows it has found all the nonblank characters, and it's why the pointer is now at column 5.

data_null__
Jade | Level 19

From the document you reference.

 

 With list input, the pointer reads until a blank is reached and then stops in the next column

 

 

novinosrin
Tourmaline | Level 20

How i understand: 

Both list and column/formatted points to 1 column to the right after reading values.

 

List input :read until delimiter is  found (this makes it an extra read--so in your example if red-3bytes read+1 until delim makes it 4, and then as mentioned above move 1 to the right)

 

Column/formatted : read exactly specified by the format width/number range in the input statement, then as usual move 1 column to the right

Tom
Super User Tom
Super User

Note also that with LIST mode it is not always SPACE characters that it is used to mark the end of a field. It is whatever characters are included in the DLM= option of the INFILE statement.  Space is the default, unless the DSD option is specified. The DSD option changes the default to comma instead.

 

Similar behavior when using the DLMSTR= option also. Cursor is left at the character after the end of the delimiter string that was found.

data_null__
Jade | Level 19

@Tom wrote:

Note also that with LIST mode it is not always SPACE characters that it is used to mark the end of a field. It is whatever characters are included in the DLM= option of the INFILE statement.  Space is the default, unless the DSD option is specified. The DSD option changes the default to comma instead.

 

Similar behavior when using the DLMSTR= option also. Cursor is left at the character after the end of the delimiter string that was found.


DSD also changes the way consecutive delimiters are handled.  I'm not sure about pointer position for consecutive delimiters, reckon I need to find out.  Cat Happy

Tom
Super User Tom
Super User

@data_null__ wrote:

@Tom wrote:

 

...

DSD also changes the way consecutive delimiters are handled.  I'm not sure about pointer position for consecutive delimiters, reckon I need to find out.  Cat Happy


I think the DSD option changes what happens when a read STARTS with the current position containing a delimiter.  Without DSD all of the leading delimiters are skipped and the read starts with the next non-delimiter.  With DSD a null value is used for the current read and the cursor advances past the delimiter. 

cosmid
Lapis Lazuli | Level 10

Sorry everyone for accepting a solution so late. I wasn't getting any notifications for this post and I thought I have asked a stupid question. Checked my email today and saw it. Again, my apologies. And thanks for all the great inputs!

 

@data_null__ I can't believe I missed it when reading the document. Thanks for pointing it out!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 2038 views
  • 6 likes
  • 5 in conversation