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

Hello!

I want to distriute some coding to our users. they shouldt be able to test, in batchjobs on z/OS, if a simple sequential file exists. 

Furthermore  they should be able to test if that existing dataset is empty .

This question is not posted fpr SAS-Datasets/-libraries, but for z/OS Datasets

I'm thinking about something like the  %SYSFUNC statement.

Thank you for help or information!

Engelbert Smets

Hallo!

Ich möchte unseren Benutzern eine Möglichkeit bieten im Batchjob unter z/OS

abzufragen, ob

- eine Datei, z.B. zugeordnet über JCL oder filename, exitiert

- eine Datei, z.B. zugeordnet über JCL oder filename, exitiert, aber leer ist.

Wohlgemerkt, es handelt sich dabei nicht um eine SAS-DAtei, sondern um ander übliche z/OS-Dateien.

Im Hinterkopf denke ich da an %SYSFUNC oder so etws.

Vielen Dank für Unterstützung!

Engelbert Smets

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

FILEEXIST() should be able to test if a file exists.  You could also try using the FOPEN() function.

An easy way to test if a file has zero records is to read it.  For example this will set the macro variable EMPTY to 1 when there are no records in the file referenced by the filename (or DD name on MVS) of MYFILE.

%let empty=0;

data _null_;

    if eof then call symputx('EMPTY','1');

    infile MYFILE  end=eof ;

   stop;

run;

View solution in original post

3 REPLIES 3
BrunoMueller
SAS Super FREQ

Die Chance eine Antwort zu bekommen, ist viel grösser wenn die Frage auf English gestellt wird.

SAS stellt die FILEEXIST und FEXIST zur Verfügung. Mit diesen Funktionen kann geprüft werden ob ein File existiert.

Um festzustellen, ob das File leer ist, muss man das File lesen, zum Beispiel mit dem DATA Step

jakarman
Barite | Level 11

Mit das Deutsch wurde ich auch auskommen. De meiste guten Handbücher und Internet Seiten sind
aber im English.  Lassen wir es zum English halten.

JCL (Job Control Language) and dataset access at the z/OS mainframe are behaving very different ot what is common at Windows or Unix.

That is:

- You cannot put an non-existing dataset into JCL

   JES-2 is skipping the job before something has run.   (first JCL-step)

- The locking on datasets is very strict organized by the use of the DISP (OLD NEW SHR).

  There are exceptions ont some types like PDS-E  or using the HFS naming approach like common in UNIX.

  That last approach is very unusual for the oldies of mainframes but it is possibe as the kernal is there.       

- Jobs that are run by a scheduler (eg TWS) normally require the verfivying of time and datasets being used/.

SAS has dedicated manual for specific Mainframe SAS language: SAS(R) 9.3 Companion for z/OS, Second Edition (DSNexist)

What are your options (You have to check with your IT support):

- bypass the TWS requirements and code SAS like the DSNexist sample

- use the TWS verifying/trigger whether a dataset exist. normally as a trigger from an other job. 

- Build a first step in the JCL that check the dataset dynamically and you next JCL-Steps being executed conditionally

- use a HFS-datasetname.

- Use the PDS-E approach als members in a shared library are not checked as long as you do not give mebernames

- use dummy-datasets with  zero records to have valid datasetnames for the JCL-JEs2 step

- Use concatenation of datasets with a default empty datset to be overwritten

- With the SAS input function use the file-var  filename option to check the real datasetname

When the goal is a collection of inputdatsets I would advice a PDS-E setup up as VBS with a lrecl of 32Kn (maximum) and a blocksize of half-track 3390.

That is the closest to the suequential way of thinking at Unix/Windos.

A Unix type (HFS) approach would be even easier but very hard to get done when your IT staff does not want you to help with that.        

---->-- ja karman --<-----
Tom
Super User Tom
Super User

FILEEXIST() should be able to test if a file exists.  You could also try using the FOPEN() function.

An easy way to test if a file has zero records is to read it.  For example this will set the macro variable EMPTY to 1 when there are no records in the file referenced by the filename (or DD name on MVS) of MYFILE.

%let empty=0;

data _null_;

    if eof then call symputx('EMPTY','1');

    infile MYFILE  end=eof ;

   stop;

run;

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!

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
  • 3 replies
  • 1451 views
  • 3 likes
  • 4 in conversation