SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
THALLA_REDDY
Obsidian | Level 7

Hi all,

 

I have to read a Mainframe PDS which is having SAS Program members in it by passing the PDS using a JCL. I have to read one by one and have to get the creation date and user_id as highlighted in below snap.

THALLA_REDDY_0-1612791589239.png

Please help me with the SAS Code logic for the same.

 

thanks in advance

thalla

5 REPLIES 5
SASJedi
Ammonite | Level 13

I no longer have access to a mainframe to test my code, but something like this should work:

data _null_;
   /* Assign a fileref to the PDS */
   _rc=filename("myPDS","mydata.my.pdsfile");
   _did=dopen("myPDS");
   if _did ne 0 then do;
      putlog "ERROR: Unable to open PDS to look at members";
      _rc=filename("myPDS");
      stop;
   end;
   do _i=1 to dnum(did);      /* Get info for each PDS member */
      MemberName=dread(did,i);
      _rc=filename("thisMem",cats("myPDS(",MemberName,")","S");
      _fid=fopen("thisMem");
      do _j=1 to foptnum(_fid);
         infoname=foptname(_fid,_j);
         infovalue=finfo(_fid,infoname);
         output;
      end;
      _rc=fclose(_fid);
      _rc=filename("thisMem");
   end;
   _rc=dclose(_did);
   _rc=filename("myPDS");
run;

Hope this at least gets you started 🙂

 

Check out my Jedi SAS Tricks for SAS Users
THALLA_REDDY
Obsidian | Level 7
thanks, this really helps me to get started
THALLA_REDDY
Obsidian | Level 7

Hi,

 

I am getting return code 1 instead of zero with this code. Can anyone help me to move forward on this?

 

thanks,

Thalla

andreas_lds
Jade | Level 19

Please post the log so that we can see what happened.

THALLA_REDDY
Obsidian | Level 7

Hi This is the code that I have created

 

OPTIONS MISSING = ' ' SYMBOLGEN;

%LET PDSNAME = %ADDTICKS(testpds.jcllib);

DATA PDSCHK;
_RC = FILENAME("MYPDS",&PDSNAME);
_DID = DOPEN("MYPDS");
IF _DID NE 0 THEN DO;
PUTLOG "ERROR: UNABLE TO OPEN PDS TO LOOK MEMBERS IN IT";
_RC = FILENAME("MYPDS");
/* STOP; */
END;
ELSE DO;
PUTLOG "PDS opened successfully";
END;
DO _I = 1 TO DNUM(_DID);
MEMBERNAME = DREAD(_DID,I);
_RC = FILENAME("THISMEM",CATS("MYPDS(",MEMBERNAME,")","S"));
_FID = FOPEN("THISMEM");

DO _J = 1 TO FOPTNUM(_FID);
INFONAME = FOPTNAME(_FID,_J);
INFOVALUE = FINFO(_FID,INFONAME);
OUTPUT;
END;
_RC = FCLOSE(_FID);
_RC = FILENAME("THISMEM");
END;
_RC = DCLOSE(_DID);
_RC = FILENAME("MYPDS");
RUN;

 

The log is 

 

NOTE: Variable I is uninitialized.
ERROR: UNABLE TO OPEN PDS TO LOOK MEMBERS IN IT
NOTE: Argument 2 to function DREAD(1, ) at line 41 column 19 is invalid.
NOTE: Argument 1 to function FOPTNUM(0) at line 44 column 19 is invalid.
ERROR: Invalid DO loop control information, either the INITIAL or TO expression is missing or the BY expression is missing, zero, or invalid.
_RC=20002 _DID=1 _I=1 MEMBERNAME= I= _FID=0 _J=1 INFONAME= INFOVALUE= _ERROR_=1 _N_=1 
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 44:19

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1932 views
  • 1 like
  • 3 in conversation