DATA Step, Macro, Functions and more

Read sas log and create a sas dataset

Occasional Contributor
Posts: 7

Read sas log and create a sas dataset

Hi ,


Can any one help me with below requirement.


1. Want to read sas log resides on unix environment through EG

2. Capture the activity what datasets they reading, from which source, finally what they are doing ( kind of monitoring user activity)

3. Finally provide the captured information.


Please provide some sample code for this.

Super User
Posts: 10,574

Re: Read sas log and create a sas dataset

Finding datasets that were written or read is rather easy, as the NOTEs always look the same and the lines containing them can be easily extracted by using the INDEX() function with the proper substrings. To determine those substrings, read a log file, it's pretty obvious.

So that is just reading a text file (use _infile_ to get the whole input buffer) and a subsetting if with the proper strings, then doing substr() to get the dataset name out of the line. Set an additional parameter containing a read/write flag, and add the logfile or program or user name as appropriate.

Then you have one observation for every dataset that was read or created.


Extracting what in particular was done is non-trivial, as it basically involves parsing the preceding step(s). Talk about writing a code parser in SAS itself.


I'd rather be content with the dataset information. Further determination of what was done in particular I'd rather leave to the good old eyeballs Mk I.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Super User
Posts: 9,840

Re: Read sas log and create a sas dataset

Sorry, this is not a contract work forum.  If you have specific questions then we can ask that, but a logcheck application is not within the confines of this forums remit.


As for your points there:

1) To read a file use the infile syntax, plenty of examples given in the SAS documentation.

2) This can go from simple to extremely complicated in a few lines of code.  How are you controlling what coders write?  I can write some very complicated macro/generated code which it would takes days to untangle, how would you capture that in your app?

3) Far to vague a question, "provide" - how, in what format - try proc print/report, or tagsets.excelxp.


Simply put, this task can be very large depending on how well controlled the inputs are.  For instance, if you tell your programmers to follow a fixed methodology, 1 step one dataset named dsX, then its quite simple.  If your analyzing complexe programs where output could be streamed around, files read, code generated, ods objects selected etc. then it becomes vastly more complicated - perhaps a step to far if you cannot currently read in a log file from Unix?


A further thought, since 9.2 there have been some tools provided by SAS to achieve simliar things to this, proc scaproc is used and that can help, here is a paper on it:

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation