Many years ago I worked on an old IBM VM/CMS box which was at end-of-life, but not-quite-yet. The platform manager had a cartoon of two old guys digging in a cemetery with the caption, "I know we buried that old mainframe around here somewhere..."
One of the old projects I was working on made extensive use of formats, but the source code of those formats was long lost. Using cntlout in proc format allowed us to edit the formats and republish them, but it frustrated the hell out of me that it was such a laborious process.
So I wrote one of the macros I'm proudest of: %genfmt. OK, it's not such a great name, but it does just that - it generates or recreates format code.
Over the years I've upgraded it a bit from its humble value beginnings, especially to include invalue (character and numeric) and picture types. Using invalues is interesting - to get the select statement to work, you have to prefix the format name with @. Not many people know that.
%genfmt(library=library, format=format name, ovrwrite=n*, sasgen=, debug=n**)
*Because the code writes out a file called format name.fmt, this stops it proceeding if this file already exists. If you don't care, or it doesn't exist, you'll get:
INFO: The format generation code is stored in file "$clevel.fmt".
in your log.
The output code's filename can be replaced by sasgen.
**Shows the code generated by the macro in the log
As a side effect, I found that it does a pretty good job of compressing format code as well. For example, here's an old format I was working on just this morning:
value $clevel '<2B' = '<2' '2B' = '2' '2P' = '2' '2A' = '2' '3B' = '3' '3P' = '3' '3A' = '3' '4B' = '4' '4P' = '4' '4A' = '4' '5B' = '5' '5P' = '5' '5A' = '5' '6B' = '6' '6P' = '6' '6A' = '6' '>6A'= '>6A' ;
I applied genfmt to it and this was spat out:
value $clevel "2A", "2B", "2P" = "2" "3A", "3B", "3P" = "3" "4A", "4B", "4P" = "4" "5A", "5B", "5P" = "5" "6A", "6B", "6P" = "6" "<2B" = "<2" ">6A" = ">6A";
There's nothing particularly clever in the code, but I have documented it pretty well, I think, so you can see what I've done and how I've done it. Note that it copes with quotes within labels, inclusive/exclusive ranges, other values, imbeded formats and, I think, pretty much everything else.
This is, as ever, open source - use it in health, and let me know if you've liked it and especially if you've found any bugs. Payment can be made in beer.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.