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

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    

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

4 REPLIES 4
FloydNevseta
Pyrite | Level 9

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.

G_I_Jeff
Obsidian | Level 7

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);

Astounding
PROC Star

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.

G_I_Jeff
Obsidian | Level 7

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 779 views
  • 0 likes
  • 3 in conversation