BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pobel
Calcite | Level 5

Hi all,

I have an question about reading data from DATALINES, here is the code:

data test;

    input test $40. @@;

datalines;

1---shorter than 80---end

;

data test1;

    input test $40. @@;

datalines;

1---shorter than 80---end

2---longer than 80----------------------------------------------but shorter than 160---end

3---shorter than 80---end

4---shorter than 80---end

;

Data set TEST has 2 records and TEST1 has 14 records. For those 14 records of TEST1, 2 came from the first data line, and 4 from each of the other 3 data lines.

I guess that when reading data from DATALINES, the number "80" should be involved with the the "Length" of  data SAS reads from each line. But I cannot figure out what the exact "RULE" is.

Any help is highly appreciated, thank you very much!

The log:

107  data test;

108      input test $40. @@;

109  datalines;

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

NOTE: The data set WORK.TEST has 2 observations and 1 variables.

NOTE: DATA statement used (Total process time):

      real time           0.00 seconds

      cpu time            0.00 seconds

111  ;

112

113  data test1;

114      input test $40. @@;

115  datalines;

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.

NOTE: The data set WORK.TEST1 has 14 observations and 1 variables.

NOTE: DATA statement used (Total process time):

      real time           0.01 seconds

      cpu time            0.00 second

Best regards!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just ask SAS to tell you how long the line is?

data _null_;

  infile cards length=len ;

  input @;

  put len= _infile_;

cards;

short line

short line

....+...10....+...20....+...30....+...40....+...50....+...60....+...70....+...80....+...90

short line

run;

len=80 short line

len=80 short line

len=160

....+...10....+...20....+...30....+...40....+...50....+...60....+...70....+...80....+...90

len=160

short line

In general it is a multiple of 80.  (IBM punch cards have 80 postions.) It seems once it bumps up past a multiple of 80 boundary it stays there.

If you are running this in background then the line length of the input stream might be longer.  If your input is from a file on an IBM mainframe or other system where the operating system can set the record length then SAS will most likely understand that.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Why not just ask SAS to tell you how long the line is?

data _null_;

  infile cards length=len ;

  input @;

  put len= _infile_;

cards;

short line

short line

....+...10....+...20....+...30....+...40....+...50....+...60....+...70....+...80....+...90

short line

run;

len=80 short line

len=80 short line

len=160

....+...10....+...20....+...30....+...40....+...50....+...60....+...70....+...80....+...90

len=160

short line

In general it is a multiple of 80.  (IBM punch cards have 80 postions.) It seems once it bumps up past a multiple of 80 boundary it stays there.

If you are running this in background then the line length of the input stream might be longer.  If your input is from a file on an IBM mainframe or other system where the operating system can set the record length then SAS will most likely understand that.

pobel
Calcite | Level 5

Tom, Thank you very much!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 895 views
  • 0 likes
  • 2 in conversation