Help using Base SAS procedures

Possible INFILE problem with my code

Accepted Solution Solved
Reply
Contributor
Posts: 73
Accepted Solution

Possible INFILE problem with my code

I have pieced together the following DATA statement with examples I've found and it runs to completion but doesn not populate the pdb. The problem I am trying to solve is to read through 10 files, checking if they exists and import thier data into a pdb. Simple enough.

DATA USER.LNX_HISTORY;

ARRAY SYS{10} $4. _TEMPORARY_  ('SYSE' 'SYSX' 'LNX1' 'LNX2' 'LNX3' 'LNX4' 'LNX5' 'LNX6' 'LNX7' 'LNX8');

DO I = 1 TO 10;

   LENGTH FILENAME $256;

   FILENAME = CATS('SYS90H.'||SYS{I}||'HISTORY.',PUT(TODAY()-1,YYMMDD6.));

   IF FILEEXIST(FILENAME) THEN DO;

  

      INFILE DUMMY END=EOF FILEVAR=FILENAME;

         DO WHILE(NOT EOF);

             INPUT

               xxxxx

               xxxxx

               xxxxx....

         END;

   END;

END;

STOP;

RUN;

I am getting sporatic results when I run this. Sometimes it reads through all allocated files and put zero observations to the pdb, sometimes it loops. I've narrowed it down to the INFILE statement but cannot figure it out yet. If anyone sees anything obvious, please thump me on the head!!

Jeff    


Accepted Solutions
Solution
‎03-28-2012 12:10 PM
Super User
Posts: 5,085

Possible INFILE problem with my code

Jeff,

The obvious head-thumper is that there is no OUTPUT statement.  Most DATA steps output a record automatically upon hitting the bottom of the DATA step at the RUN statement.  This code loops, then stops before getting there, so it should have an OUTPUT statement after the INPUT statement.

View solution in original post


All Replies
Frequent Contributor
Posts: 101

Possible INFILE problem with my code

1. When constructing the filename, should a period be before HISTORY, e.g. sys90h.syse.history.120327?

2. It's been a while since I've worked on a mainframe. If these are os/390 files, don't the segments of the filename have to begin with an alpha character? So the segment with the date must begin with a-z.

Contributor
Posts: 73

Possible INFILE problem with my code

SAS_Bigot,

Yes your correct and I'm sorry I miss-typed the statement:

FILENAME = CATS('SYS90H.'||SYS{I}||'.HISTORY.D',PUT(TODAY()-1,YYMMDD6.));

Guess I was in a hurry!

I know the FILENAME statement is correct because when I test the DO loops with the following code it works as expected:

DATA USER.LNX_HISTORY;

ARRAY SYS{10} $4. _TEMPORARY_ ('SYSE' 'SYSX' 'LNX2' 'LNX3' 'LNX4' 'LNX5' 'LNX6' 'LNX7' 'LNX8');

DO I = 1 TO 10;

LENGTH FILENAME $256;

FILENAME = CATS('SYS90H.'||SYS{I}||'.HISTORY.D',PUT(TODAY()-1,YYMMDD6.));

IF FILEEXISTS(FILENAME) THEN DO;

    PUT FILENAME;

END;

END;

STOP;

RUN;

I recieve the following:

SYS90D.SYSE.HISTORY.D120327

SYS90D.SYSX.HISTORY.D120327

SYS90D.LNX2.HISTORY.D120327

SYS90D.LNX3.HISTORY.D120327

SYS90D.LNX4.HISTORY.D120327

SYS90D.LNX5.HISTORY.D120327

Those are the current allocated files on the system this code is running on. So it has to do something with the INFILE statement, either witht EOF not being set or I'm creating a loop with the DO WHILE(NOT EOF);

Solution
‎03-28-2012 12:10 PM
Super User
Posts: 5,085

Possible INFILE problem with my code

Jeff,

The obvious head-thumper is that there is no OUTPUT statement.  Most DATA steps output a record automatically upon hitting the bottom of the DATA step at the RUN statement.  This code loops, then stops before getting there, so it should have an OUTPUT statement after the INPUT statement.

Contributor
Posts: 73

Re: Possible INFILE problem with my code

Astouding,

DUHH!! Thank you!! I knew it was something very stupid I was overlooking!! I don't know where I lost the output statement along the way....

This is the first time I've tried doing something like this inside loops so I'm glad it works now.

Jeff

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 254 views
  • 0 likes
  • 3 in conversation