BookmarkSubscribeRSS Feed
Ksharp
Super User

NO. actually according to SAS9.2 documentation(dictionary), it would be almost 2G ,

Sorry.Chris

using a file may do a trick.

ChrisNZ
Tourmaline | Level 20

Mmm, weird.

The documentation for the LRECL system option states 32kb max, but the doc for the LRECL filename option states 1Gb max for windows and unix.

I missed that change. I wonder why the discrepancy between the 2 lengths. That discrepancy sure threw me off in any case.

No need for streaming then, all good.

Sorry for misleading you DJDaniel.

Thanks for the update KSharp.

Mmm weird again: It looks like sas did an half-baked enhancement. lrecl is longer but then variable _infile_ causes errors.

The following code should be valid but throws an error. What's going on sas?

data T (compress=yes);

  infile TEST lrecl=500000 pad missover termstr=CRLF dlm=';' dsd;

  input;

L=length(_infile_);

run;

yields:

ERROR: The LRECL / LINESIZE for infile TEST exceeds the maximum allowable length for an _INFILE_ or _INFILE_= variable (32,767).

The DATA STEP will not be executed.

so all is not so clear it seems.

DanielKaiser
Pyrite | Level 9

Thanks Ksharp,

that seems to be the right way.

I understand most of it.

But what do i need to change to use an infile not instead of pasting my lines in to the code?

I have 45 flatfile, each has about 4000 lines...

Ksharp
Super User

Your data looks very complex. You 'd better post a file .

Ksharp
Super User

OK.

1) copy your data firstly.

2)replace : with = by using notepad++ or  other text editor.

and due to your complicated situation, you need to deep process data more .

data have;
 infile 'c:\temp\testdata.txt' firstobs=3  lrecl=200000 expandtabs ;
 input (host ports status  index seq os) (= $400.);
run;


Ksharp

ChrisNZ
Tourmaline | Level 20

This reads the file you posted directly (no prior editing needed). No long record there though.

data OUT(compress=yes);

infile 'c:\router.txt' lrecl=400 pad missover dlm='09'x;

input  @'Host:' HOST : $200. @'Status:' STATUS : $4. ;

if HOST ne '';

if STATUS='Up' then

   input @'Ports:' PORTS : $200. @'OS:' OS : $200. @'Seq Index:' SEQINDEX : $200. @'Seq:' SEQ : $200. ;

run;

DanielKaiser
Pyrite | Level 9

Thanks Chris, Thanks Ksharp,

chris your output looks good but does not solve my problem that the maximum length of the Ports Variable is at 32k. but in some of the files i have a Lenght of that string thats much longer.

DanielKaiser
Pyrite | Level 9

A combination of your Code and the code of Achilles seems interessting.

ChrisNZ
Tourmaline | Level 20

I dont see how Achille's code can work. Variable _infile_ cannot exceed 32k in length.

ChrisNZ
Tourmaline | Level 20

Why didn't you upload a file which includes the data that causes you problems?

DanielKaiser
Pyrite | Level 9

You'r right that would have been better,

in this file there are two observations with more than 32767characters

https://www.dropbox.com/s/svyo7c62gg8kdo8/textdaten.txt

Ksharp
Super User

OK. It waste me lots of time. As I mentioned before, you need process it more after that.

data _null_;
file 'c:\temp\x.txt' lrecl=200000;
infile 'c:\temp\textdaten.txt' lrecl=200000  recfm=n;
input x $char1. @@;     
retain max n;
if x=':' then do;x='=';     n=0;end;
 else if x=',' then do;
                      n+1; max=max(max,n) ;
                           name= cats('p',n,'=');
                           put +(-1) ' ' name @;
                           call symputx('max',max);
                           return;
                         end;
put +(-1) x @;
 if _n_ eq 50000 then stop;
run;
%put &max;

data have;
 infile 'c:\temp\x.txt'  lrecl=200000  firstobs=3  expandtabs ;
 input (host Status ports p1 - p&max state os index seq ) (= $2000.) ;
 if _n_ eq 500 then stop;
run;

Ksharp

DanielKaiser
Pyrite | Level 9

Ohh... it works. much thanks to you both for your time and your knowledge.

It was a really big help to me und i learned a lot too.

ChrisNZ
Tourmaline | Level 20

data OUT(compress=yes);

  infile 'c:\router2.txt' lrecl=250000 pad missover dlm='09'x;

  length LASTSTR $40.;

  drop LASTSTR PORTNB LASTCOMMAPOS L;

  array PORTS[8] $32767. ;

  input  @'Host:' HOST : $200. @'Status:' STATUS : $4. ;

  if HOST ne '';

  if STATUS='Up' then

     input @'Ports:'         PORTS1   : $32767.

           @'OS:'            OS       : $200.

           @'Seq Index:'     SEQINDEX : $200.

           @'Seq:'           SEQ      : $200.

           @'Ignored State:' IGNORED  : $20. @;

  L=length(PORTS1);

  PORTNB=1;

  do while (L > 32700) ;                                    * string full, read more;

    LASTCOMMAPOS=find(PORTS[PORTNB],',',-32767);            * look for last comma;

    substr(PORTS[PORTNB],LASTCOMMAPOS+1)='';                * remove last item as it may be truncated;

    LASTSTR=substr(PORTS[PORTNB],length(PORTS[PORTNB])-40); * get string-end;             

    PORTNB+1;                                               * read into next ports variabl

    input @1 @(strip(LASTSTR)) PORTS[PORTNB] : $32767. @;   * read data after string-end;

    L=length(PORTS[PORTNB]);                                * see if new string still full;

end;

run;

Similar to the previous code with extra looping at the end to read the long port string.

Ksharp's code puts each port in a separate variable, this one reads in bulk adn should be much faster.

You'll have to modify the loop to read in smaller chunks if you want.

And please use this to learn and experiment, don't use it blindly.

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
  • 29 replies
  • 10206 views
  • 5 likes
  • 7 in conversation