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

 

The enclosed code is not inputting two alphanumeric variables which are in the enclosed txt file. How to read this data in? The software just hangs up and nothing happens?  Thanks.

 

Mary A. Marion

 

%let dirdata=/folders/myshortcuts/611/data/Week 03/HWdata/;
data names;
infile "&dirdata.top-1000-baby-boy-names.mm.txt"
/* termstr=CRLF */ truncover lrecl=512 pad ;
*input name $ rank2 comma9. @@;
input name: $30. rank2 $ @@;
run;
proc print; run; *963 obs, should be 1000 obs;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data have;
infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt' lrecl=32767;
input name: $30. rank2 $ @@	;
run;

1163  data have;
1164  infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt' lrecl=32767;
1165  input name: $30. rank2 $ @@ ;
1166  run;

NOTE: The infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt' is:
      Filename=C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt,
      RECFM=V,LRECL=32767,File Size (bytes)=13220,
      Last Modified=30Sep2019:05:45:16,
      Create Time=30Sep2019:05:45:16

NOTE: 488 records were read from the infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt'.
      The minimum record length was 8.
      The maximum record length was 415.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.HAVE has 1000 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
data have;
infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt' lrecl=32767;
input name: $30. rank2 $ @@	;
run;

1163  data have;
1164  infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt' lrecl=32767;
1165  input name: $30. rank2 $ @@ ;
1166  run;

NOTE: The infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt' is:
      Filename=C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt,
      RECFM=V,LRECL=32767,File Size (bytes)=13220,
      Last Modified=30Sep2019:05:45:16,
      Create Time=30Sep2019:05:45:16

NOTE: 488 records were read from the infile 'C:\Users\sony\Desktop\top-1000-baby-boy-names.mm.txt'.
      The minimum record length was 8.
      The maximum record length was 415.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.HAVE has 1000 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

MaryA_Marion
Lapis Lazuli | Level 10
novinosrin, Thanks. Is there something special about lrecl=32767? I tried using lrecl=512 and got an error. MM
ballardw
Super User

@MaryA_Marion wrote:
novinosrin, Thanks. Is there something special about lrecl=32767? I tried using lrecl=512 and got an error. MM

Depends on the error;

Post the code with the error message from the log, Copy from the log and paste into a code box opened with the forum's {I} or "running man" icon.

 

TRUNCOVER really doesn't make a lot of sense when using the @@ to hold the input line though.

 

I have to say that whoever compiled that source file has issues though unless there is some information that is important that has been removed. Having from one to thirty or so names on a single row and the names in neither rank order or alphabetical order is pretty odd IMHO.

Tom
Super User Tom
Super User

You cannot use TRUNCOVER option on the INFILE statement in combination with the double trailing @ on INPUT statement.

The former says to stay on the same line after reading past the end of the data on the line. The later says to keep on the same line after the end of the data step iteration.  The combination means that it will never read past the first line of the input text.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1303 views
  • 2 likes
  • 4 in conversation