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