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?
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?
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.
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 **/
/
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.