DATA Step, Macro, Functions and more

Comment reading

Reply
Contributor
Posts: 25

Comment reading

Hi,

 

I need to report the comments written in SAS programs, as there are many of them I need help

 

Programs which reside in z/Os PDS members contain single and multi line comments, I need to generate a report which contains the comments present in the program (i.e. PDS member) with the name of that PDS member

 

For ex. if below program is preset in members called A01 & A02 in PDS library ABC.DEF.GHI

 

* OPTIONS ;
  OPTIONS MLOGIC MPRINT SYMBOLGEN ;

* DEFINE A MACRO CALLED READ ;
  %MACRO READ ;
     DATA _NULL_ ;
       PUT 'READING' ;
     RUN ;
  %MEND READ ;

/* EXECUTE THE MACRO WHICH HAS BEEN - 
   ALREADY DEFINED */

  %READ ;

Then the reportt should be as below

 

 

ABC.DEF.GHI(A01)

 

* OPTIONS ;

 

* DEFINE A MACRO CALLED READ ;

 

/* EXECUTE THE MACRO WHICH HAS BEEN -
   ALREADY DEFINED */

 

ABC.DEF.GHI(A02)

 

* OPTIONS ;

 

* DEFINE A MACRO CALLED READ ;

 

/* EXECUTE THE MACRO WHICH HAS BEEN -
   ALREADY DEFINED */

 

The code which generates above report need to take PDS name as the input parameter, read all the members inside that PDS and generate the report as above.

 

Could anyone please help?

Super User
Posts: 5,257

Re: Comment reading

A simple data step that uses SAS programs as INFILE filenames, and just keep observations that starts with *.

For the /* */ on multiple line, you probably need some kind of retain logic to make that work.

I hope that program are well structured so that comments isn't part of lines, then you logic will rapidly build up.

 

Perhaps the SAS code analyzer is a more solid alternative, even if can't you 100% the output you are looking for?

Data never sleeps
Super User
Super User
Posts: 7,401

Re: Comment reading

I am afraid what you are asking for is for someone to write a text parser for you.  This isn't a specific question.  It can get quite complicated, sure its simple to open a file for read, and read it in line by line searching for "/*", "*" etc., however you also have to then contend with nested comments, missing end of strings, * being used as multiplier, commented code etc.  Its not a trivial task.

 

This is a good example of why documentation is far more important than programming in the modern world.  If you follow Software Development Lifecycle process, your Functional Design Specification will already have the neccessary information contained within it, version history would be in the Version Control software, as would changes, so no comments. 

Contributor
Posts: 25

Re: Comment reading

Thank you;
I thought it is not as simple as it sounds!!
Super User
Posts: 5,083

Re: Comment reading

It would become an easy problem in the future, if you could impose coding standards for comments.  While there are a few possibilities for workable standards, here would be one way to create the right environment going forward.

 

The original comments:

 

* OPTIONS;

 

* DEFINE A MACRO CALLED READ;

 

/* EXECUTE THE MACRO WHICH HAS BEEN -

   ALREADY DEFINED */

 

The new style:

 

/** OPTIONS                            **/

 

/** DEFINE A MACRO CALLED READ         **/

 

/** EXECUTE THE MACRO WHICH HAS BEEN - **/

/** ALREADY DEFINED                    **/

 

 

Super User
Super User
Posts: 7,401

Re: Comment reading

Whilst coding standards would help, I can pretty much guarantee that with a few different programmers you will start to see non-compliance with it, mistakes, not being updated in line with code etc.  Even two programmers find it hard.  This is why I would go with a standard header which has minimal information, and leave the Version control software to handle changes/comments etc.  You can even force information via hooks if necessary.  

Super User
Posts: 17,831

Re: Comment reading

Beyond what everyone else has stated, there are code parsers for comments for SAS that do exist. Search lexjansen.com and/or Google in general.

Here's a quick result from <1min of googling. Good Luck.
http://www.lexjansen.com/phuse/2014/ad/AD09.pdf
Ask a Question
Discussion stats
  • 6 replies
  • 289 views
  • 5 likes
  • 5 in conversation