Published on :
Utility MIXTE

Generating SAS documentation in Markdown and HTML

This code is also available in: Deutsch Español Français
Awaiting validation
The script initializes several work tables (alias_list, order_list, header_list, scrub_list) via DATA steps with datalines. These tables define section aliases, section order, headers, and sections to hide for the %code_diary macro. The %code_diary macro is then called to analyze a main SAS© file specified by input_main_file and generate output Markdown files. Finally, the %convert_markdown_to_html macro is used to transform one of the generated Markdown files into an HTML document.
Data Analysis

Type : MIXTE


Initial data (alias, order, header, and scrub lists) are created internally via DATALINES blocks. However, the called macros (%code_diary and %convert_markdown_to_html) process external files (SAS files for %code_diary and Markdown files for %convert_markdown_to_html).

1 Code Block
Macro Inclusion
Explanation :
These lines include two SAS macros (`code_diary` and `convert_markdown_to_html`) from the location specified by the `&MACRO_ROOT` macro variable. These macros are essential for the script's documentation generation functionality.
Copied!
1%include "&MACRO_ROOT.code_diary.sas";
2%include "&MACRO_ROOT.convert_markdown_to_html.sas";
3 
2 Code Block
DATA STEP Data
Explanation :
This DATA step creates the `work.alias_list` work table which contains short and long keyword pairs. It is used by the `%code_diary` macro to manage section aliases in the generated documentation.
Copied!
1DATA work.alias_list;
2 INFILE DATALINES;
3 INPUT short_keyword $1-10 long_keyword $11-50;
4 
5 DATALINES;
6excl exclusion
7stat statistics
8;
3 Code Block
DATA STEP Data
Explanation :
This DATA step creates the `work.order_list` work table which defines the display order of different sections in the documentation generated by the `%code_diary` macro.
Copied!
1DATA work.order_list;
2 INFILE DATALINES;
3 INPUT keyword $1-20 order_no 21-25;
4 
5 DATALINES;
6todo -30
7exclusion -20
8exclusion.time -19
9exclusion.person -18
10methods -10
11no_keyword 0
12;
4 Code Block
DATA STEP Data
Explanation :
This DATA step creates the `work.header_list` work table which associates keywords with section headers for the documentation produced by the `%code_diary` macro.
Copied!
1DATA work.header_list;
2 INFILE DATALINES;
3 INPUT keyword $1-15 header $16-50;
4 
5 DATALINES;
6exclusion Exclusion criteria
7person Subjects
8time Time periods
9todo Task list
10;
5 Code Block
DATA STEP Data
Explanation :
This DATA step creates the `work.scrub_list` work table which lists keywords for sections to be hidden or scrubbed during documentation generation by the `%code_diary` macro.
Copied!
1DATA work.scrub_list;
2 INFILE DATALINES;
3 INPUT keyword $1-15;
4 
5 DATALINES;
6todo
7regex
8;
6 Code Block
Macro Call
Explanation :
This call to the `%code_diary` macro is the main function of the script. It takes a SAS file (`&DEMO_ROOT.project_main.sas`) as input and, using the previously defined lists (`alias_list`, `order_list`, `header_list`, `scrub_list`), generates two Markdown documentation files (`output-coder.md` and `output-for-all.md`) in the `&DEMO_ROOT` directory.
Copied!
1%code_diary(
2 input_main_file = &DEMO_ROOT.project_main.sas,
3 out_dir = &DEMO_ROOT,
4 out_file = OUTPUT-coder.md,
5 out_file_scrubbed = OUTPUT-for-all.md,
6 debug_mode = 0,
7 section_aliases = work.alias_list,
8 section_order = work.order_list,
9 section_headers = work.header_list,
10 sections_scrubbed = work.scrub_list
11);
7 Code Block
Macro Call
Explanation :
This call to the `%convert_markdown_to_html` macro takes the previously generated Markdown file `output-for-all.md` and converts it into an HTML file (`output-for-all.htm`), also in the `&DEMO_ROOT` directory.
Copied!
1%convert_markdown_to_html(
2 in_file_md = "&DEMO_ROOT.output-for-all.md",
3 out_file_html = "&DEMO_ROOT.output-for-all.htm",
4 debug_mode = 0
5);
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.