diff --git a/README.md b/README.md
index 38182f3..dac1e37 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,13 @@
# SMILE - Smart SAS Macros
+
SMILE stands for Smart SAS Macros - an Intuitive Library Extension
-
+
Smile contains various small SAS macros supporting various tasks of a SAS programmer. Some macros are inspired by other open source macros and some by available papers. A complete overview can be seen below. More detailed documentation can be found in the macro headers or on the [documentation page](https://katjaglassconsulting.github.io/SMILE-SmartSASMacros/).
-
-# Macro Overview
-
+
+## Macro Overview
+
The following SAS macros are currently available:
-
+
Macro | Description
---|---
smile_attr_var |Function-style macro to return a variable attribute of a dataset. The following attributes are available: VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT
@@ -15,28 +16,36 @@ smile_attrn |Function-style macro to return a numeric attribute of a dataset. Th
smile_ods_document_flat_label |Flat navigation and optionally re-label navigation for ODS DOCUMENT. The navigation bookmark level is reduced to one level only. Optionally a label can be applied to all content items or the navigation label can be removed completely.
smile_pdf_merge |Merge multiple PDF files and create one bookmark entry per PDF file with PROC GROOVY and open-source Tool PDFBox
smile_pdf_read_bookmarks |Read PDF Bookmarks into a SAS dataset with the variables level, title and page
+smile_replace_in_text_files |Replace text from all files contained in a folder with a different text
smile_url_check |Check existence of URL and store result in return code, information can optionally be printed to the log
smile_url_download |Downloads a file from an URL and store it locally on OUTFILE. Additionally return code can be stored and information can optionally be printed to the log.
-
-# Getting Started
-
-The macros can be cloned or downloaded directly from the GitHub repository to use this within any SAS environment. The macros has been developed under SAS 9.4 Unix, but are likely to run on other operating systems and also under other SAS versions like from SAS 9.2.
-
+
+## Getting Started
+
+The macros can be cloned or downloaded directly from the GitHub repository to use this within any SAS environment. The macros has been developed under SAS 9.4 Unix, but are likely to run on other operating systems and also under other SAS versions like from SAS 9.2.
+
To use the macros in any program, these can be included single by single via `%INCLUDE "";` or the folder where the macros are located can be included into the SASAUTOS path `OPTIONS SASAUTOS=(, SASAUTOS);`. The macros can also be stored into a SAS Macro store and used from there.
-The repository is using the following structure:
+The macros could easily be made available in any SAS environment with internet connection with the following two statements:
+```sas
+FILENAME macros URL "https://raw.githubusercontent.com/KatjaGlassConsulting/SMILE-SmartSASMacros/main/all.sas";
+%INCLUDE macros;
+```
+
+The repository is using the following structure:
+
Folder | Content
--- |---
macros | This folder contains the core macros
programs | General programs can be found here - test_* programs are available to check the functionality of macros
results | Outputs generated through programs
-
-# License
-
+
+## License
+
The macros and programs are using the MIT-License. See [LICENSE](https://github.com/KatjaGlassConsulting/SMILE-SmartSASMacros/blob/main/LICENSE) for more information.
-
-# Contact
-
+
+## Contact
+
These macros has been developed by Katja Glass Consulting. Feel free to reach me through my [website](https://www.glacon.eu) or via [LinkedIn](https://www.linkedin.com/in/katja-glass-369022167/).
-
+
diff --git a/all.sas b/all.sas
new file mode 100644
index 0000000..40921bc
--- /dev/null
+++ b/all.sas
@@ -0,0 +1,956 @@
+
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Purpose : This file contains all the macros in a single file - which means it can be 'included' in SAS with just 2 lines of code:
+%* filename mc url "https://raw.githubusercontent.com/KatjaGlassConsulting/SMILE-SmartSASMacros/main/all.sas";
+%* %INCLUDE mc;
+%* Author : Katja Glass
+%************************************************************************************************************************;
+
+OPTIONS NOQUOTELENMAX;
+
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_attrc
+%* Parameters : DATA - name of the SAS dataset
+%* ATTRIB - SAS ATTRC keyword (e.g. TYPE, LIB, LABEL, SORTEDBY, ...)
+%*
+%* Purpose : Function-style macro to return a character attribute of a dataset. The following attributes are available:
+%* CHARSET, COMPRESS, DATAREP, ENCODING, ENCRYPT, ENGINE, LABEL, LIB, MEM, MODE, MTYPE, SORTEDBY, SORTLVL,
+%* SORTSEQ, TYPE
+%*
+%* ExampleProg: ../programs/test_smile_attrc.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : Main programming parts are coming from attrc.sas macro from Roland Rashleigh-Berry who
+%* has published his code under the unlicence license in his utility package
+%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%PUT library of dataset: %smile_attrc(sashelp.class, lib);
+PROC SORT DATA=sashelp.class OUT=class; BY sex name; RUN;
+%PUT class is sorted by: %smile_attrc(class, SORTEDBY);
+%PUT sashelp.class is sorted by: %smile_attrc(sashelp.class, SORTEDBY);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_attrc(data, attrib) / MINOPERATOR MINDELIMITER=',';
+ %LOCAL dsid rc macro;
+
+ %LET macro = &sysmacroname;
+
+ %* check: ATTRIB must contain valid options;
+ %IF NOT (%UPCASE(&attrib) IN (CHARSET,COMPRESS,DATAREP,ENCODING,ENCRYPT,ENGINE,LABEL,LIB,MEM,MODE,MTYPE,
+ SORTEDBY,SORTLVL,SORTSEQ,TYPE))
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib).;
+ -1
+ %RETURN;
+ %END;
+
+ %* perform action and put value for processing;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
+ -1
+ %END;
+ %ELSE %DO;
+ %SYSFUNC(attrc(&dsid,&attrib))
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %END;
+%MEND smile_attrc;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_attrn
+%* Parameters : DATA - name of the SAS dataset
+%* ATTRIB - SAS ATTRN keyword (e.g. NOBS, CRDTE, ...)
+%*
+%* Purpose : Function-style macro to return a numeric attribute of a dataset. The following attributes are available:
+%* ALTERPW, ANOBS, ANY, ARAND, ARWU, AUDIT, AUDIT_DATA, AUDIT_BEFORE, AUDIT_ERROR, CRDTE, ICONST, INDEX,
+%* ISINDEX, ISSUBSET, LRECL, LRID, MAXGEN, MAXRC, MODTE, NDEL, NEXTGEN, NLOBS, NLOBSF, NOBS, NVARS, PW, RADIX,
+%* READPW, REUSE, TAPE, WHSTMT, WRITEPW
+%*
+%* ExampleProg: ../programs/test_smile_attrn.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : Main programming parts are coming from attrn.sas macro from Roland Rashleigh-Berry who
+%* has published his code under the unlicence license in his utility package
+%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%PUT Number of observations: %smile_attrn(sashelp.class, nobs);
+%IF %smile_attrn(sashelp.class, nvars) > 0 %THEN %PUT Dataset has variables;
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_attrn(data, attrib) / MINOPERATOR MINDELIMITER=',';
+ %LOCAL dsid rc macro;
+
+ %LET macro = &sysmacroname;
+
+ %* check: ATTRIB must contain valid options;
+ %IF NOT (%UPCASE(&attrib) IN (ALTERPW,ANOBS,ANY,ARAND,ARWU,AUDIT,AUDIT_DATA,AUDIT_BEFORE,AUDIT_ERROR,CRDTE,ICONST,INDEX,
+ ISINDEX,ISSUBSET,LRECL,LRID,MAXGEN,MAXRC,MODTE,NDEL,NEXTGEN,NLOBS,NLOBSF,NOBS,NVARS,PW,RADIX,
+ READPW,REUSE,TAPE,WHSTMT,WRITEPW))
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib).;
+ -1
+ %RETURN;
+ %END;
+
+ %* perform action and put value for processing;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
+ -1
+ %END;
+ %ELSE %DO;
+ %SYSFUNC(attrn(&dsid,&attrib))
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %END;
+%MEND smile_attrn;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_attr_var
+%* Parameters : DATA - name of the SAS dataset
+%* VAR - name of variable
+%* ATTRIB - SAS variable attrib keyword (e.g. VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT)
+%*
+%* Purpose : Function-style macro to return a variable attribute of a dataset. The following attributes are available:
+%* VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT
+%*
+%* ExampleProg: ../programs/test_smile_attr_var.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : Main programming parts are coming from attrv.sas macro from Roland Rashleigh-Berry who
+%* has published his code under the unlicence license in his utility package
+%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%PUT VARTYPE for name: %smile_attr_var(sashelp.class, name, vartype);
+%PUT VARTYPE for age: %smile_attr_var(sashelp.class, age, vartype);
+%PUT VARLABEL for name: %smile_attr_var(sashelp.class, name, varlabel);
+%PUT VARLEN for name: %smile_attr_var(sashelp.class, name, varlen);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_attr_var(data, var, attrib);
+ %LOCAL dsid rc macro varnum;
+
+ %LET macro = &sysmacroname;
+
+ %* check: ATTRIB must contain valid options;
+ %IF %UPCASE(&attrib) NE VARTYPE AND
+ %UPCASE(&attrib) NE VARLEN AND
+ %UPCASE(&attrib) NE VARLABEL AND
+ %UPCASE(&attrib) NE VARFMT AND
+ %UPCASE(&attrib) NE VARINFMT
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib) - only the following are supported:;
+ %PUT ¯o - VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT;
+ -1
+ %RETURN;
+ %END;
+
+ %* perform action and put value for processing;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
+ -1
+ %END;
+ %ELSE %DO;
+ %LET varnum = %SYSFUNC(VARNUM(&dsid,&var));
+ %IF &varnum LT 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Variable VAR (&var) does not exist in DATA (&data).;
+ -1
+ %RETURN;
+ %END;
+ %SYSFUNC(&attrib(&dsid,&varnum))
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %END;
+%MEND smile_attr_var;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_ods_document_flat_label
+%* Parameters : DOCUMENT - ODS Document item store
+%* LABEL - One label to apply on first element, all other labels are removed (optional),
+%* if not provided, labels are just rearranged and additional BY-labels removed
+%* BOOKMARKLABEL - Indicator whether to use Bookmark Labels if none is specified (YES Default),
+%* if LABEL is missing and BOOKMARKLABEL = NO, all labels are removed
+%*
+%* Purpose : Flat navigation and optionally re-label navigation for ODS DOCUMENT. The navigation bookmark level is
+%* reduced to one level only. Optionally a label can be applied to all content items or the navigation label
+%* can be removed completely.
+%* Comment : The navigation in PDF documents can be one level only with this macro. CONTENTS="" must be applied to
+%* the PROC REPORT as option and additionally for a BREAK BEFORE PAGE option.
+%* Issues : The table of contents created per default by SAS (ODS PDF option TOC) is not linking the pages correctly when
+%* using BY groups and having one ODS DOCUMENT with multiple outputs, using single ODS DOCUMENTS (one per each output)
+%* then this is working correctly. In such a case, do use not a TOC or create an own TOC, e.g. like described here:
+%* https://www.mwsug.org/proceedings/2012/S1/MWSUG-2012-S125.pdf
+%*
+%* ExampleProg: ../programs/test_smile_ods_document_flat_label.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-15
+%* License : MIT
+%*
+%* Reference : A nice overview of ODS DOCUMENT can be found here: https://support.sas.com/resources/papers/proceedings12/273-2012.pdf
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%*This will flatten the navigation and use the labels originally set with ODS PROCLABEL;
+%smile_ods_document_flat_label(document=doc_reports);
+
+%*This will flatten the navigation and use the label "Table 1.1.1" applied to all items of this store;
+%smile_ods_document_flat_label(document=doc_report1, label=Table 1.1.1);
+
+%*This will flatten the navigation and use no navigation label at all (no navigation link at all for these items);
+%smile_ods_document_flat_label(document=doc_report1, label=, bookmarklabel = NO);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_ods_document_flat_label(document=, label=, bookmarkLabel = yes);
+
+ %LOCAL macro _temp;
+ %LET macro = &sysmacroname;
+ %LET _temp = -1;
+
+%*;
+%* Error handling I;
+%*;
+
+ %* check: DOCUMENT must be specified;
+ %IF %LENGTH(&document) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DOCUMENT parameter is required. Macro will abort;
+ %RETURN;
+ %END;
+
+ %* check: BOOKMARKLABEL must be YES or NO;
+ %IF %UPCASE(&bookmarkLabel) NE YES AND %UPCASE(&bookmarkLabel) NE NO
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - BOOKMARKLABEL parameter must either be NO or YES. Macro will abort;
+ %RETURN;
+ %END;
+
+ %* check - DOCUMENT must be an existing item store in WORK;
+ PROC SQL NOPRINT;
+ SELECT 1 INTO :_temp FROM SASHELP.VMEMBER
+ WHERE libname="WORK" AND memname="%UPCASE(&document)" AND memtype = "ITEMSTOR";
+ RUN;QUIT;
+ %IF &_temp NE 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DOCUMENT (&document) is no existing ODS DOCUMENT. Macro will abort;
+ %RETURN;
+ %END;
+
+%*;
+%* Read information;
+%*;
+
+ ODS SELECT NONE;
+ PROC DOCUMENT NAME = &document;
+ LIST / DETAILS LEVELS=all;
+ ODS OUTPUT PROPERTIES = _props;
+ RUN;QUIT;
+ ODS SELECT ALL;
+
+%*;
+%* Error handling II;
+%*;
+
+ %* check: DOCUMENT must contain content;
+ %LET _temp = -1;
+ PROC SQL NOPRINT;
+ SELECT nobs INTO :_temp FROM SASHELP.VTABLE WHERE libname="WORK" AND memname="_PROPS";
+ RUN;QUIT;
+ %IF &_temp = 0
+ %THEN %DO;
+ %PUT %STR(WAR)NING: ¯o - DOCUMENT (&document) does not contain any observations - no action done;
+ %RETURN;
+ %END;
+
+%*;
+%* Processing;
+%*;
+
+ %* create a generic processing for PROC DOCUMENT;
+ %* Step 1: move all reports to /all and apply label;
+ DATA _NULL_;
+ SET _props END=_eof;
+ ATTRIB coreLabel FORMAT=$200.;
+ RETAIN coreLabel;
+ RETAIN _count 1 _first 0 _core 0;
+
+ IF _N_ = 1
+ THEN DO;
+ CALL EXECUTE("PROC DOCUMENT NAME=&document;");
+ END;
+
+ IF COUNT(path,"\") = 1 AND type = "Dir"
+ THEN DO;
+ _core = 1;
+ %IF %UPCASE(&bookmarkLabel) NE YES
+ %THEN %DO;
+ CALL MISSING(coreLabel);
+ PUT "updateOdsDocument - No label is used";
+ %END;
+ %ELSE %IF %LENGTH("&label") > 2
+ %THEN %DO;
+ coreLabel = "&label";
+ %END;
+ %ELSE %DO;
+ coreLabel = label;
+ _first = 0;
+
+ %END;
+ END;
+
+ IF type NE "Dir" AND _core
+ THEN DO;
+ CALL EXECUTE('MOVE ' || STRIP(path) || ' to \all;');
+ IF _first = 0
+ THEN CALL EXECUTE('SETLABEL \all#' || STRIP(PUT(_count,BEST.)) || " '" || STRIP(coreLabel) || "';");
+ _first = 1;
+ _count = _count + 1;
+ END;
+
+ IF _eof
+ THEN DO;
+ CALL EXECUTE('RUN;QUIT;');
+ END;
+ RUN;
+
+ %* Step 2: remove all old hierarchies;
+ DATA _NULL_;
+ SET _props END=_eof;
+ IF _N_ = 1
+ THEN CALL EXECUTE("PROC DOCUMENT NAME=&document;");
+ IF COUNT(path,"\") = 1 AND type = "Dir"
+ THEN CALL EXECUTE('DELETE ' || STRIP(path) || ";");
+ IF _eof
+ THEN CALL EXECUTE('RUN;QUIT;');
+ RUN;
+
+%*;
+%* Cleanup;
+%*;
+
+ PROC DATASETS LIB=WORK;
+ DELETE _props;
+ RUN;
+
+%MEND smile_ods_document_flat_label;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_pdf_merge
+%* Parameters : DATA - Input dataset containing INFILE and BOOKMARK variable,
+%* INFILE containing single pdf files (one file per observation),
+%* BOOKMARK containing the corresponding bookmark label for this file
+%* OUTFILE - Output PDF file (not in quotes)
+%* PDFBOX_JAR_PATH - Path and jar file name for PDFBOX open source tool, e.g. &path/pdfbox-app-2.0.22.jar
+%* SOURCEFILE - Optional SAS program file where PROC GROOVY code is stored, default is TEMP (only temporary)
+%* RUN_GROOVY - NO/YES indicator whether to run the final GROOVY code (default YES)
+%*
+%* Purpose : Merge multiple PDF files and create one bookmark entry per PDF file with PROC GROOVY and open-source Tool PDFBox
+%* Comment : Make sure to download PDFBOX, e.g. from here https://pdfbox.apache.org/download.html - the full "app" version
+%* Issues : "unable to resolve class" messages mean the PDFBOX is not provided correctly.
+%* "ERROR: PROCEDURE GROOVY cannot be used when SAS is in the lock down state." means that your SAS environment
+%* does not support PROC GROOVY, for this the macro cannot run the groovy code.
+%* "WARNUNG: Removed /IDTree from /Names dictionary, doesn't belong there" - this message is coming from PDFBox.
+%*
+%* ExampleProg: ../programs/test_smile_pdf_merge.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-01-29
+%* License : MIT
+%*
+%* Reference : A paper explaining how to use PDFBOX with PROC GROOVY also for TOC is available in the following paper
+%* (https://www.lexjansen.com/phuse/2019/ct/CT05.pdf)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+DATA content;
+ ATTRIB inFile FORMAT=$255.;
+ ATTRIB bookmark FORMAT=$255.;
+ inFile = "&inPath/output_1.pdf"; bookmark = "Table 1"; OUTPUT;
+ inFile = "&inPath/output_2.pdf"; bookmark = "Table 2"; OUTPUT;
+ inFile = "&inPath/output_3.pdf"; bookmark = "Table 3"; OUTPUT;
+RUN;
+%smile_pdf_merge(
+ data = content
+ , outfile = &outPath/merged_output.pdf
+ , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
+ , sourcefile = &progPath/groovy_call.sas
+ , run_groovy = YES
+);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_pdf_merge(data = , outfile = , pdfbox_jar_path = , sourcefile = TEMP, run_groovy = YES);
+
+ %LOCAL macro;
+ %LET macro = &sysmacroname;
+
+%*;
+%* Error handling I - parameter checks;
+%*;
+
+ %* check: existence of required parameters (DATA, OUTFILE, PDFBOX_JAR_PATH), abort;
+ %* check: existence of parameter SOURCEFILE, if not use TEMP;
+ %* check: RUN_GROOVY must be NO or YES, abort;
+
+ %IF %LENGTH(&data) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA parameter is requried. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&outfile) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - OUTFILE parameter is requried. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&pdfbox_jar_path) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH parameter is requried. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&sourcefile) = 0
+ %THEN %DO;
+ %PUT %STR(WAR)NING: ¯o - SOURCEFILE parameter is needed - TEMP will be used.;
+ %LET sourcefile = TEMP;
+ %END;
+
+ %IF %UPCASE(&run_groovy) NE YES AND %UPCASE(&run_groovy) NE NO
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - RUN_GROOVY parameter must be NO or YES. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %* check: PDFBOX_JAR_PATH must exist and must be a ".jar" file;
+ %IF %SYSFUNC(FILEEXIST(&pdfbox_jar_path)) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH file does not exist. Macro will abort.;
+ %RETURN;
+ %END;
+ %IF %UPCASE(%SCAN(&pdfbox_jar_path,-1,.)) NE JAR
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH must be a ".jar" file. Macro will abort.;
+ %RETURN;
+ %END;
+
+%*;
+%* Preparations;
+%*;
+
+ %* include quotes around sourcefile if not available;
+ DATA _NULL_;
+ ATTRIB path FORMAT=$500.;
+ path = SYMGET('sourcefile');
+ IF UPCASE(STRIP(path)) NE "TEMP"
+ THEN DO;
+ IF SUBSTR(sourcefile,1,1) NE '"' AND SUBSTR(sourcefile,1,1) NE "'"
+ THEN DO;
+ CALL SYMPUT('sourcefile','"' || STRIP(path) || '"');
+ END;
+ END;
+ RUN;
+
+%*;
+%* Error handling II - data checks;
+%*;
+
+ %LOCAL dsid rc error;
+ %LET error = 0;
+
+ %* check: existence of data, contains observations, contains variables infile and bookmark;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist. Macro will abort.;
+ %RETURN;
+ %END;
+ %ELSE %IF %SYSFUNC(ATTRN(&dsid,NLOBS)) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not contain any observations. Macro will abort.;
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %RETURN;
+ %END;
+ %ELSE %IF %SYSFUNC(VARNUM(&dsid,infile)) = 0 OR %SYSFUNC(VARNUM(&dsid,bookmark)) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not contain required variables (infile and bookmark). Macro will abort.;
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %RETURN;
+ %END;
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+
+ %* check: files in variable "infile" must exist;
+ %* update BOOKMARK labels, replace double quotes;
+ DATA _smile_indat;
+ SET &data;
+ RETAIN _smile_msg 0;
+ IF FILEEXIST(infile) = 0
+ THEN DO;
+ PUT "%STR(ERR)OR: INFILE does not exist: " infile " - Macro will abort.";
+ CALL SYMPUT('error','1');
+ END;
+ IF INDEX(bookmark,'"') > 0 AND _smile_msg = 0
+ THEN DO;
+ PUT "%STR(WAR)NING: Double quotes are not supported for BOOKMARK texts and are removed.";
+ _smile_msg = 1;
+ END;
+ bookmark = TRANWRD(bookmark,'"','');
+ RUN;
+
+ %IF &error NE 0
+ %THEN %DO;
+ %GOTO end_macro;
+ %END;
+
+%*;
+%* Create PROC GROOVY program file;
+%*;
+
+ FILENAME cmd &sourcefile;
+
+ DATA _NULL_;
+ FILE cmd LRECL=5000;
+ SET _smile_indat END=_eof;
+ IF _N_ = 1
+ THEN DO;
+ PUT "PROC GROOVY;";
+ PUT " ADD CLASSPATH = ""&pdfbox_jar_path"";";
+ PUT " SUBMIT;";
+ PUT ;
+ PUT "import org.apache.pdfbox.multipdf.PDFMergerUtility;";
+ PUT "import org.apache.pdfbox.pdmodel.PDDocument;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;";
+ PUT "import java.io.File;";
+ PUT ;
+ PUT "public class PDFMerge2 {";
+ PUT " public static void main(String[] args) {";
+ PUT;
+ PUT @8 "//Instantiating PDFMergerUtility class";
+ PUT @8 "PDFMergerUtility PDFmerger = new PDFMergerUtility();";
+ PUT ;
+ PUT @8 "//Setting the destination file";
+ PUT @8 "PDFmerger.setDestinationFileName(""&outfile"");";
+ PUT ;
+ PUT @8 "//adding the source files";
+ END;
+ PUT @8 "PDFmerger.addSource(new File(""" inFile +(-1) """));";
+ IF _eof
+ THEN DO;
+ PUT @8 "PDFmerger.mergeDocuments(null);";
+ END;
+ RUN;
+
+ DATA _NULL_;
+ FILE cmd LRECL=5000 MOD;
+ ATTRIB _temp FORMAT=$200.;
+ SET _smile_indat END=_eof;
+ IF _N_ = 1
+ THEN DO;
+ PUT @8 "//Open created document";
+ PUT @8 "PDDocument document;";
+ PUT @8 "PDPageDestination pageDestination;";
+ PUT @8 "PDOutlineItem bookmark;";
+ PUT @8 "document = PDDocument.load(new File(""&outfile""));";
+ PUT ;
+ PUT @8 "//Create a bookmark outline";
+ PUT @8 "PDDocumentOutline documentOutline = new PDDocumentOutline();";
+ PUT @8 "document.getDocumentCatalog().setDocumentOutline(documentOutline);";
+ PUT @8 ;
+ PUT @8 "int currentPage = 0;";
+ END;
+
+ _temp = SCAN(inFile,-1,"/\");
+ PUT @8 "//Include file " _temp;
+ PUT @8 "pageDestination = new PDPageFitWidthDestination();";
+ PUT @8 "pageDestination.setPage(document.getPage(currentPage));";
+ PUT @8 "bookmark = new PDOutlineItem();";
+ PUT @8 "bookmark.setDestination(pageDestination);";
+ PUT @8 "bookmark.setTitle(""" bookmark +(-1) """);";
+ PUT @8 "documentOutline.addLast(bookmark);";
+ PUT ;
+ PUT @8 "//Change currentPage number";
+ PUT @8 "currentPage += PDDocument.load(new File(""" inFile +(-1) """)).getNumberOfPages();";
+ PUT ;
+ IF _eof
+ THEN DO;
+ PUT @8 "//save document";
+ PUT @8 "document.save(""&outfile"");";
+ PUT ;
+ PUT "}}";
+ PUT "endsubmit;";
+ PUT "quit;";
+ END;
+ RUN;
+
+%*;
+%* Optionally execute PROC GROOVY code;
+%*;
+
+ %IF %UPCASE(&run_groovy) = YES
+ %THEN %DO;
+ %PUT ¯o: Run Groovy Program;
+ %PUT ¯o: The following warning might come from PDFBox: %STR(WAR)NING: Removed /IDTree from /Names dictionary ...;
+ %INCLUDE cmd;
+ %END;
+
+%end_macro:
+
+%*;
+%* cleanup;
+%*;
+
+ FILENAME cmd;
+
+ PROC DATASETS LIB=WORK NOWARN NOLIST;
+ DELETE _smile_indat;
+ RUN;
+
+
+%MEND;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_pdf_read_bookmarks
+%* Parameters : PDFFILE - name of PDF file with bookmarks
+%* OUTDAT - output dataset
+%* PDFBOX_JAR - path and jar file name for PDFBOX open source tool, e.g. &path/pdfbox-app-2.0.22.jar
+%*
+%* Purpose : Read PDF Bookmarks into a SAS dataset with the variables level, title and page
+%* Comment : Make sure to download PDFBOX, e.g. from here https://pdfbox.apache.org/download.html - the full "app" version
+%* Issues : "unable to resolve class" messages mean the PDFBOX is not provided correctly.
+%* "ERROR: PROCEDURE GROOVY cannot be used when SAS is in the lock down state." means that your SAS environment
+%* does not support PROC GROOVY, for this the macro cannot run the groovy code.
+%*
+%* ExampleProg: ../programs/test_smile_pdf_read_bookmarks.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-13
+%* License : MIT
+%*
+%* Reference : PDFBox contains a lot of useful functionalities (https://pdfbox.apache.org)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%smile_pdf_read_bookmarks(pdfFile = /ods_document_flat1.pdf,
+ outdat = book_flat1,
+ pdfbox_jar_path = /pdfbox-app-2.0.22.jar)
+
+%smile_pdf_read_bookmarks(pdfFile = /ods_document_noflat1.pdf,
+ outdat = book_noflat1,
+ pdfbox_jar_path = /pdfbox-app-2.0.22.jar)
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_pdf_read_bookmarks(pdfFile = , outdat = , pdfbox_jar_path = );
+
+ %LOCAL jsonFile;
+
+ FILENAME jsonFile TEMP;
+ %LET jsonFile = %SYSFUNC(PATHNAME(jsonFile));
+
+ FILENAME _rdbkpd TEMP;
+ DATA _NULL_;
+ FILE _rdbkpd LRECL=5000;
+
+ PUT 'PROC GROOVY;';
+ PUT ' ADD CLASSPATH = "' "&pdfbox_jar_path" '";';
+ PUT ' SUBMIT;';
+ PUT ;
+ PUT ' import java.io.File;';
+ PUT ' import java.io.FileWriter;';
+ PUT ' import java.io.IOException;';
+ PUT ' import java.io.PrintWriter;';
+ PUT ' import java.util.ArrayList;';
+ PUT ;
+ PUT ' import org.apache.pdfbox.pdmodel.PDDocument;';
+ PUT ' import org.apache.pdfbox.pdmodel.PDPage;';
+ PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;';
+ PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;';
+ PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode;';
+ PUT ;
+ PUT ' public class PDFReadBookmarks {';
+ PUT ;
+ PUT ' public static void main(String[] args) throws IOException {';
+ PUT ' ArrayList aBookmarks = new ArrayList();';
+ PUT ;
+ PUT ' // Read the PDF document and investigate bookmarks into a list (JSON formatted)';
+ PUT ' PDDocument document = PDDocument.load(new File("' "&pdffile" '"));';
+ PUT ' PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();';
+ PUT ' addBookmark(aBookmarks, document, outline, 1);';
+ PUT ' document.close();';
+ PUT ;
+ PUT ' // Print bookmark information into a file';
+ PUT ' FileWriter fileWriter = new FileWriter("' "&jsonFile" '");';
+ PUT ' PrintWriter printWriter = new PrintWriter(fileWriter);';
+ PUT ' printWriter.print(aBookmarks);';
+ PUT ' printWriter.close();';
+ PUT ' }';
+ PUT ;
+ PUT ' static public void addBookmark(ArrayList bookmarks, PDDocument document, PDOutlineNode bookmark, int level) throws IOException';
+ PUT ' {';
+ PUT ' PDOutlineItem current = bookmark.getFirstChild();';
+ PUT ' while (current != null)';
+ PUT ' {';
+ PUT ' PDPage currentPage = current.findDestinationPage(document);';
+ PUT ' Integer pageNumber = document.getDocumentCatalog().getPages().indexOf(currentPage) + 1;';
+ PUT ' String text = "\n{\"level\":" + level + ", \"title\":\"" + current.getTitle() + "\", \"page\":" + pageNumber + "}";';
+ PUT ' bookmarks.add(text);';
+ PUT ' addBookmark(bookmarks, document, current, level + 1);';
+ PUT ' current = current.getNextSibling();';
+ PUT ' }';
+ PUT ' }';
+ PUT ' }';
+ PUT 'ENDSUBMIT;';
+ PUT 'QUIT;';
+
+ RUN;
+ %INCLUDE _rdbkpd;
+
+ LIBNAME jsonCont JSON "&jsonFile";
+
+ DATA &outdat(DROP=ordinal_root);
+ SET jsonCont.root;
+ RUN;
+
+%MEND smile_pdf_read_bookmarks;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_url_check
+%* Parameters : URL - http(s) URL which should be checked in quotes
+%* RETURN - return code variable (scope should be global)
+%* INFO - NO/YES indicator to print information to the log
+%*
+%* Purpose : Check existence of URL and store result in return code, information can optionally be printed to the log
+%* Comment : Return codes are 0 - url found, 999 - no url provided,
+%* 998 - url not provided in quotes, otherwise html-return code (e.g. 404 file not found)
+%*
+%* ExampleProg: ../programs/test_smile_url_check.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : The idea from this macro is coming from a paper by Joseph Henry - The ABCs of PROC HTTP
+%* (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+OPTIONS NONOTES;
+%GLOBAL rc;
+%smile_url_check(url="https://github.com/phuse-org/phuse-scripts/blob/master/whitepapers/scriptathons/central/dummy.sas");
+%PUT &rc;
+%smile_url_check(url="https://github.com/phuse-org/phuse-scripts/blob/master/whitepapers/scriptathons/central/Box_Plot_Baseline.sas");
+%PUT &rc;
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_url_check(url=, return=rc, info=NO);
+
+ %LOCAL macro issue;
+ %LET macro = &sysmacroname;
+ %LET issue = 0;
+
+ %* check: URL must be provided;
+ %IF %LENGTH(&url) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - URL must be provided.;
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ %LET &return = 999;
+ %END;
+ %RETURN;
+ %END;
+
+ %* check: URL must be provided in quotes;
+ DATA _NULL_;
+ ATTRIB url FORMAT=$2000.;
+ url = SYMGET('url');
+ IF NOT (SUBSTR(url,1,1) IN ("'",'"') AND SUBSTR(url,LENGTH(url)) IN ("'",'"'))
+ THEN DO;
+ PUT "ERR" "OR: ¯o - URL must be provided in quotes.";
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ CALL SYMPUT("&return", "998");
+ %END;
+ CALL SYMPUT("issue", "1");
+ END;
+ RUN;
+ %IF &issue = 1
+ %THEN %RETURN;
+
+ %* perform URL check;
+ FILENAME out TEMP;
+ FILENAME hdrs TEMP;
+
+ PROC HTTP URL=&url
+ HEADEROUT=hdrs;
+ RUN;
+
+ DATA _NULL_;
+ INFILE hdrs SCANOVER TRUNCOVER;
+ INPUT @'HTTP/1.1' code 4. message $255.;
+
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ IF code=200
+ THEN CALL SYMPUT("&return", "0");
+ ELSE CALL SYMPUT("&return", code);
+ %END;
+ %IF %UPCASE(&info) NE NO
+ %THEN %DO;
+ PUT "Return Code: " code;
+ PUT "Return Message: " message;
+ %END;
+ RUN;
+
+ FILENAME out;
+ FILENAME hdrs;
+
+%MEND smile_url_check;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_url_download
+%* Parameters : URL - http(s) URL which should be checked in quotes
+%* OUTFILE - output file provided in quotes
+%* RETURN - return code variable (scope should be global)
+%* INFO - NO/YES indicator to print information to the log
+%*
+%* Purpose : Downloads a file from an URL and store it locally on OUTFILE. Additionally return code can be stored and
+%* information can optionally be printed to the log.
+%* Comment : Return codes are 0 - URL found, 999 - no URL or OUTFILE provided,
+%* 998 - URL or OUTFILE not provided in quotes, otherwise html-return code (e.g. 404 file not found)
+%*
+%* Author : Katja Glass
+%* Creation : 2021-01-04
+%* License : MIT
+%*
+%* Reference : The idea from this macro is coming from a paper by Joseph Henry - The ABCs of PROC HTTP
+%* (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%smile_url_download(url="http://sas.cswenson.com/downloads/macros/AddFormatLib.sas",
+ outfile="/folders/myshortcuts/git/sas-dev/packages/chris_sas_macros/AddFormatLib.sas",
+ info=NO,
+ return=);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_url_download(url=, outfile=, info=NO, return=);
+
+ %LOCAL macro issue;
+ %LET macro = &sysmacroname;
+ %LET issue = 0;
+
+ %* check: URL and OUTFILE must be provided;
+ %IF %LENGTH(&url) = 0 OR %LENGTH(&outfile)
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - URL and OUTFILE must be provided.;
+ %IF %LENGTH(&return) > 0
+ %THEN %LET &return = 999;
+ %RETURN;
+ %END;
+
+ %* check: URL and OUTFILE must be provided in quotes;
+ DATA _NULL_;
+ ATTRIB url FORMAT=$2000.;
+ ATTRIB outfile FORMAT=$2000.;
+ url = SYMGET('url');
+ IF NOT (SUBSTR(url,1,1) IN ("'",'"') AND SUBSTR(url,LENGTH(url)) IN ("'",'"'))
+ THEN DO;
+ PUT "ERR" "OR: ¯o - URL must be provided in quotes.";
+ %IF %LENGTH(&return) > 0
+ %THEN CALL SYMPUT("&return", "998");
+ CALL SYMPUT("issue", "1");
+ END;
+ outfile = SYMGET('outfile');
+ IF NOT (SUBSTR(outfile,1,1) IN ("'",'"') AND SUBSTR(outfile,LENGTH(outfile)) IN ("'",'"'))
+ THEN DO;
+ PUT "ERR" "OR: ¯o - OUTFILE must be provided in quotes.";
+ %IF %LENGTH(&return) > 0
+ %THEN CALL SYMPUT("&return", "998");
+ CALL SYMPUT("issue", "1");
+ END;
+ RUN;
+ %IF &issue = 1
+ %THEN %RETURN;
+
+ FILENAME out &outfile;
+ FILENAME hdrs TEMP;
+
+ PROC HTTP URL=&url
+ OUT=out
+ HEADEROUT=hdrs;
+ RUN;
+
+ DATA _NULL_;
+ INFILE hdrs SCANOVER TRUNCOVER;
+ INPUT @'HTTP/1.1' code 4. message $255.;
+
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ IF code=200
+ THEN CALL SYMPUT("&return", "0");
+ ELSE CALL SYMPUT("&return", code);
+ %END;
+ %IF %UPCASE(&info) NE NO
+ %THEN %DO;
+ PUT "Return Code: " code;
+ PUT "Return Message: " message;
+ %END;
+ RUN;
+
+%MEND smile_url_download;
diff --git a/docs/index.md b/docs/index.md
index d8c1c7f..baabff4 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,4 +1,15 @@
-# Overview
+# SMILE - Smart SAS Macros
+
+SMILE stands for Smart SAS Macros - an Intuitive Library Extension
+
+The macros could easily be made available in any SAS environment with internet connection with the following two statements:
+
+```sas
+FILENAME macros URL "https://raw.githubusercontent.com/KatjaGlassConsulting/SMILE-SmartSASMacros/main/all.sas";
+%INCLUDE macros;
+```
+
+## Macro Overview
The following macros are available in the SMILE - Smart SAS Macros - an Intuitive Library Extension.
@@ -10,6 +21,7 @@ smile_attrn |Function-style macro to return a numeric attribute of a dataset. Th
smile_ods_document_flat_label |Flat navigation and optionally re-label navigation for ODS DOCUMENT. The navigation bookmark level is reduced to one level only. Optionally a label can be applied to all content items or the navigation label can be removed completely.
smile_pdf_merge |Merge multiple PDF files and create one bookmark entry per PDF file with PROC GROOVY and open-source Tool PDFBox
smile_pdf_read_bookmarks |Read PDF Bookmarks into a SAS dataset with the variables level, title and page
+smile_replace_in_text_files |Replace text from all files contained in a folder with a different text
smile_url_check |Check existence of URL and store result in return code, information can optionally be printed to the log
smile_url_download |Downloads a file from an URL and store it locally on OUTFILE. Additionally return code can be stored and information can optionally be printed to the log.
@@ -172,6 +184,32 @@ PDFBOX_JAR |path and jar file name for PDFBOX open source tool, e.g. &path/pdfbo
+### smile_replace_in_text_files
+
+Key | Description
+---|---
+Name |smile_replace_in_text_files
+Purpose |Replace text from all files contained in a folder with a different text
+SAS Version |SAS 9.4
+Author |Katja Glass
+Date |2021-03-05
+Example Program |../programs/test_smile_replace_in_text_files.sas
+
+********************************************
+
+The following parameters are used:
+
+Parameter | Description
+---|---
+INPATH |input directory (no quotes)
+OUTPATH |output directory, if same as INPATH, files are overwritten (no quotes)
+REPLACE_FROM |text which should be replaced (with quotes)
+REPLACE_WITH |text that should newly be added (with quotes)
+FILETYPE |extension of file types which should be processed, e.g. sas or txt (optional)
+
+
+
+
### smile_url_check
Key | Description
diff --git a/docs/smile_replace_in_text_files.md b/docs/smile_replace_in_text_files.md
new file mode 100644
index 0000000..d6b5579
--- /dev/null
+++ b/docs/smile_replace_in_text_files.md
@@ -0,0 +1,200 @@
+# Macro SMILE_REPLACE_IN_TEXT_FILES
+
+Replace text from all files contained in a folder with a different text
+
+- Author: Katja Glass
+- Date: 2021-03-05
+- SAS Version: SAS 9.4
+- License: MIT
+- Example Program: [test_smile_replace_in_text_files](test_smile_replace_in_text_files.md)
+
+## Parameters
+
+Parameter | Description
+---|---
+INPATH |input directory (no quotes)
+OUTPATH |output directory, if same as INPATH, files are overwritten (no quotes)
+REPLACE_FROM |text which should be replaced (with quotes)
+REPLACE_WITH |text that should newly be added (with quotes)
+FILETYPE |extension of file types which should be processed, e.g. sas or txt (optional)
+
+
+
+
+## Examples
+
+```
+%* replace the default root path in all example files;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/programs,
+ outpath = /home/u49641771/smile/programs,
+ replace_from = '%LET root = /folders/myshortcuts/git/SMILE-SmartSASMacros;',
+ replace_to = '%LET root = /home/u49641771/smile;');
+
+%* replace all tabls with four spaces;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/programs,
+ outpath = /home/u49641771/smile/programs/blub,
+ replace_from = '09'x,
+ replace_to = ' ');
+
+%* replace all zero numbers with x in the output;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/results,
+ outpath = /home/u49641771/smile/results/mod,
+ replace_from = '0',
+ replace_to = 'x',
+ filetype = lst);
+```
+
+## Macro
+
+``` sas linenums="1"
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_replace_in_text_files
+%* Parameters : INPATH - input directory (no quotes)
+%* OUTPATH - output directory, if same as INPATH, files are overwritten (no quotes)
+%* REPLACE_FROM - text which should be replaced (with quotes)
+%* REPLACE_WITH - text that should newly be added (with quotes)
+%* FILETYPE - extension of file types which should be processed, e.g. sas or txt (optional)
+%*
+%* Purpose : Replace text from all files contained in a folder with a different text
+%*
+%* ExampleProg: ../programs/test_smile_replace_in_text_files.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-03-05
+%* License : MIT
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%* replace the default root path in all example files;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/programs,
+ outpath = /home/u49641771/smile/programs,
+ replace_from = '%LET root = /folders/myshortcuts/git/SMILE-SmartSASMacros;',
+ replace_to = '%LET root = /home/u49641771/smile;');
+
+%* replace all tabls with four spaces;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/programs,
+ outpath = /home/u49641771/smile/programs/blub,
+ replace_from = '09'x,
+ replace_to = ' ');
+
+%* replace all zero numbers with x in the output;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/results,
+ outpath = /home/u49641771/smile/results/mod,
+ replace_from = '0',
+ replace_to = 'x',
+ filetype = lst);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_replace_in_text_files(
+ inpath = ,
+ outpath = ,
+ replace_from = ,
+ replace_to = ,
+ filetype =
+);
+
+ %LOCAL macro;
+ %LET macro = &sysmacroname;
+
+ %IF %SYSFUNC(FILEEXIST("&inpath")) < 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - INPATH folder does not exist: &inpath.;
+ %RETURN;
+ %END;
+
+ %IF %SYSFUNC(FILEEXIST("&outpath")) < 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - OUTPATH folder does not exist: &inpath.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&replace_from) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - REPLACE_FROM must be provided.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&replace_to) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - REPLACE_FROM must be provided.;
+ %RETURN;
+ %END;
+
+ %* read all files (ignore those without dot (folders));
+ FILENAME myPath "&inpath";
+ DATA _dir (KEEP=filename);
+ ATTRIB filename FORMAT=$200.;
+ list = DOPEN('myPath');
+ IF list > 0
+ THEN DO;
+ DO i = 1 to dnum(list);
+ filename = TRIM(DREAD(list,i));
+ %IF %LENGTH(&filetype) > 0
+ %THEN %DO;
+ IF INDEX(UPCASE(filename),"%UPCASE(.&filetype)") > 0
+ THEN OUTPUT;
+ %END;
+ %ELSE %DO;
+ IF INDEX(filename,".") > 0
+ THEN OUTPUT;
+ %END;
+ END;
+ END;
+ rc = CLOSE(list);
+ RUN;
+ FILENAME myPath;
+
+ %* re-create all files using a TRANWRD to perform replacement;
+ DATA _NULL_;
+ SET _dir;
+ ATTRIB cmd FORMAT=$1000.;
+ ATTRIB from FORMAT=$1000.;
+ ATTRIB to FORMAT=$1000.;
+ from = SYMGET('replace_from');
+ to = SYMGET('replace_to');
+ %* create three filenames (input, output, temporary in-between (needed if input=output));
+ CALL EXECUTE('FILENAME _rep_tmp TEMP;');
+ cmd = "FILENAME _rep_in '&inpath/" || STRIP(filename) || "';";
+ CALL EXECUTE(cmd);
+ cmd = "FILENAME _rep_out '&outpath/" || STRIP(filename) || "';";
+ CALL EXECUTE(cmd);
+ %* replace texts and create temporary file;
+ CALL EXECUTE('DATA _NULL_;');
+ CALL EXECUTE(' INFILE _rep_in LRECL=2000 END=_eof;');
+ CALL EXECUTE(' FILE _rep_tmp LRECL=2000;');
+ CALL EXECUTE(' ATTRIB line FORMAT=$2000.;');
+ CALL EXECUTE(' INPUT;');
+ CALL EXECUTE(' line = _INFILE_;');
+ cmd = "line = TRANWRD(line," || STRIP(from) || ", " || STRIP(to) || ');';
+ PUT cmd = ;
+ CALL EXECUTE(cmd);
+ CALL EXECUTE(' IF LENGTHN(line) = 0 THEN PUT;');
+ CALL EXECUTE(' ELSE DO;');
+ CALL EXECUTE(' pos = LENGTHN(line) - LENGTHN(STRIP(line)) + 1;');
+ CALL EXECUTE(' PUT @pos line;');
+ CALL EXECUTE(' END;');
+ CALL EXECUTE('RUN;');
+ %* store temporary file as final file;
+ CALL EXECUTE('DATA _NULL_;');
+ CALL EXECUTE(" rc=FCOPY('_rep_tmp', '_rep_out');");
+ CALL EXECUTE('RUN;');
+ RUN;
+
+ PROC DATASETS LIB=WORK NOLIST;
+ DELETE _dir;
+ RUN;
+
+%MEND smile_replace_in_text_files;
+```
+
diff --git a/docs/test_smile_attr_var.md b/docs/test_smile_attr_var.md
index b304089..fd10e0c 100644
--- a/docs/test_smile_attr_var.md
+++ b/docs/test_smile_attr_var.md
@@ -1,65 +1,65 @@
-# TEST_SMILE_ATTR_VAR
-
-Example program for macro calls of %smile_attr_var
-
- - Author : Katja Glass
- - Creation : 2021-02-15
- - SAS Version: SAS 9.4
- - License : MIT
-
-
-initialize macros
-
-```sas
-%LET root = ;
-OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
-```
-
-
-
-
-## Example 1 - simple examples
-
-
-```sas
-%PUT VARTYPE for name: %smile_attr_var(sashelp.class, name, vartype);
-%PUT VARTYPE for age: %smile_attr_var(sashelp.class, age, vartype);
-%PUT VARLABEL for name: %smile_attr_var(sashelp.class, name, varlabel);
-%PUT VARLEN for name: %smile_attr_var(sashelp.class, name, varlen);
-```
-
-
-
-
-**Log Output:**
-
-```
-VARTYPE for name: C
-VARTYPE for age: N
-VARLABEL for name:
-VARLEN for name: 8
-```
-
-
-## Example 2 - error case examples
-
-
-```sas
-%PUT data does not exist: %smile_attr_var(dummy, name, varlen);
-%PUT variable does not exist: %smile_attr_var(sashelp.class, dummy, varlen);
-%PUT invalid attribute: %smile_attr_var(sashelp.class, name, dummy);
-```
-
-
-**Log Output:**
-
-```
-ERROR: SMILE_ATTR_VAR - DATA (dummy) does not exist.
-data does not exist: -1
-ERROR: SMILE_ATTR_VAR - Variable VAR (dummy) does not exist in DATA (sashelp.class).
-variable does not exist: -1
-ERROR: SMILE_ATTR_VAR - Invalid value for ATTRIB (dummy) - only the following are supported:
-SMILE_ATTR_VAR - VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT
-invalid attribute: -1
-```
-
+# TEST_SMILE_ATTR_VAR
+
+Example program for macro calls of %smile_attr_var
+
+ - Author : Katja Glass
+ - Creation : 2021-02-15
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+initialize macros
+
+```sas
+%LET root = ;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+```
+
+
+
+
+## Example 1 - simple examples
+
+
+```sas
+%PUT VARTYPE for name: %smile_attr_var(sashelp.class, name, vartype);
+%PUT VARTYPE for age: %smile_attr_var(sashelp.class, age, vartype);
+%PUT VARLABEL for name: %smile_attr_var(sashelp.class, name, varlabel);
+%PUT VARLEN for name: %smile_attr_var(sashelp.class, name, varlen);
+```
+
+
+
+
+**Log Output:**
+
+```
+VARTYPE for name: C
+VARTYPE for age: N
+VARLABEL for name:
+VARLEN for name: 8
+```
+
+
+## Example 2 - error case examples
+
+
+```sas
+%PUT data does not exist: %smile_attr_var(dummy, name, varlen);
+%PUT variable does not exist: %smile_attr_var(sashelp.class, dummy, varlen);
+%PUT invalid attribute: %smile_attr_var(sashelp.class, name, dummy);
+```
+
+
+**Log Output:**
+
+```
+ERROR: SMILE_ATTR_VAR - DATA (dummy) does not exist.
+data does not exist: -1
+ERROR: SMILE_ATTR_VAR - Variable VAR (dummy) does not exist in DATA (sashelp.class).
+variable does not exist: -1
+ERROR: SMILE_ATTR_VAR - Invalid value for ATTRIB (dummy) - only the following are supported:
+SMILE_ATTR_VAR - VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT
+invalid attribute: -1
+```
+
diff --git a/docs/test_smile_attrc.md b/docs/test_smile_attrc.md
index 4781ac2..2b1112b 100644
--- a/docs/test_smile_attrc.md
+++ b/docs/test_smile_attrc.md
@@ -1,79 +1,79 @@
-# TEST_SMILE_ATTRC
-
-Example program for macro calls of %smile_attrc
-
- - Author : Katja Glass
- - Creation : 2021-02-18
- - SAS Version: SAS 9.4
- - License : MIT
-
-
-Initialize macros
-
-```sas
-%LET root = ;
-OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
-```
-
-
-
-
-## Example 1 - simple examples
-
-
-
-Create test data
-
-```sas
-DATA class(LABEL="SASHELP Example Dataset");
- SET sashelp.class;
-RUN;
-PROC SORT DATA=class; BY sex; RUN;
-```
-
-
-
-Call macros
-
-```sas
-%PUT Class label: %smile_attrc(class, label);
-%PUT Class sort vars: %smile_attrc(class, sortedby);
-%PUT Class library: %smile_attrc(sashelp.class, lib);
-%PUT Class encoding: %smile_attrc(sashelp.class, encoding);
-```
-
-
-
-
-**Log Output:**
-
-```
-Class label: SASHELP Example Dataset
-Class sort vars: Sex
-Class library: SASHELP
-Class encoding: us-ascii ASCII (ANSI)
-```
-
-
-
-
-## Example 2 - error case examples
-
-
-```sas
-%PUT invalid data: %smile_attrc(sashelp.class2, nobs);
-%PUT invalid attribute: %smile_attrc(sashelp.class, dummy);
-```
-
-
-
-
-**Log Output:**
-
-```
-ERROR: SMILE_ATTRC - Invalid value for ATTRIB (nobs).
-invalid data: -1
-ERROR: SMILE_ATTRC - Invalid value for ATTRIB (dummy).
-invalid attribute: -1
-```
-
+# TEST_SMILE_ATTRC
+
+Example program for macro calls of %smile_attrc
+
+ - Author : Katja Glass
+ - Creation : 2021-02-18
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+Initialize macros
+
+```sas
+%LET root = ;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+```
+
+
+
+
+## Example 1 - simple examples
+
+
+
+Create test data
+
+```sas
+DATA class(LABEL="SASHELP Example Dataset");
+ SET sashelp.class;
+RUN;
+PROC SORT DATA=class; BY sex; RUN;
+```
+
+
+
+Call macros
+
+```sas
+%PUT Class label: %smile_attrc(class, label);
+%PUT Class sort vars: %smile_attrc(class, sortedby);
+%PUT Class library: %smile_attrc(sashelp.class, lib);
+%PUT Class encoding: %smile_attrc(sashelp.class, encoding);
+```
+
+
+
+
+**Log Output:**
+
+```
+Class label: SASHELP Example Dataset
+Class sort vars: Sex
+Class library: SASHELP
+Class encoding: us-ascii ASCII (ANSI)
+```
+
+
+
+
+## Example 2 - error case examples
+
+
+```sas
+%PUT invalid data: %smile_attrc(sashelp.class2, nobs);
+%PUT invalid attribute: %smile_attrc(sashelp.class, dummy);
+```
+
+
+
+
+**Log Output:**
+
+```
+ERROR: SMILE_ATTRC - Invalid value for ATTRIB (nobs).
+invalid data: -1
+ERROR: SMILE_ATTRC - Invalid value for ATTRIB (dummy).
+invalid attribute: -1
+```
+
diff --git a/docs/test_smile_attrn.md b/docs/test_smile_attrn.md
index e81bdfd..97f37ab 100644
--- a/docs/test_smile_attrn.md
+++ b/docs/test_smile_attrn.md
@@ -1,71 +1,71 @@
-# TEST_SMILE_ATTRN
-
-Example program for macro calls of %smile_attrn
-
- - Author : Katja Glass
- - Creation : 2021-02-15
- - SAS Version: SAS 9.4
- - License : MIT
-
-
-initialize macros
-
-```sas
-%LET root = ;
-OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
-```
-
-
-
-
-## Example 1 - simple examples
-
-
-```sas
-%PUT Class NOBS(1): %smile_attrn(sashelp.class, nobs);
-%PUT Class NOBS(2): %smile_attrn(sashelp.class(WHERE=(age=16)), nobs);
-%PUT Class NLOBS: %smile_attrn(sashelp.class(WHERE=(age=16)), nlobs);
-%PUT Class NLOBSF: %smile_attrn(sashelp.class(WHERE=(age=16)), nlobsf);
-%PUT Class ANOBS(1): %smile_attrn(sashelp.class, ANOBS);
-%PUT Class ANOBS(2): %smile_attrn(sashelp.class(WHERE=(age=1)), ANOBS);
-%PUT Class NVARS: %smile_attrn(sashelp.class, NVARS);
-```
-
-
-
-
-**Log Output:**
-
-```
-Class NOBS(1): 19
-Class NOBS(2): 19
-Class NLOBS: 19
-Class NLOBSF: -1
-Class ANOBS(1): 1
-Class ANOBS(2): 1
-Class NVARS: 5
-```
-
-
-
-
-## Example 2 - error case examples
-
-
-```sas
-%PUT invalid data: %smile_attrn(sashelp.class2, nobs);
-%PUT invalid attribute: %smile_attrn(sashelp.class, dummy);
-```
-
-
-
-
-**Log Output:**
-
-```
-ERROR: SMILE_ATTRN - DATA (sashelp.class2) does not exist.
-invalid data: -1
-ERROR: SMILE_ATTRN - Invalid value for ATTRIB (dummy).
-invalid attribute: -1
-```
-
+# TEST_SMILE_ATTRN
+
+Example program for macro calls of %smile_attrn
+
+ - Author : Katja Glass
+ - Creation : 2021-02-15
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+initialize macros
+
+```sas
+%LET root = ;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+```
+
+
+
+
+## Example 1 - simple examples
+
+
+```sas
+%PUT Class NOBS(1): %smile_attrn(sashelp.class, nobs);
+%PUT Class NOBS(2): %smile_attrn(sashelp.class(WHERE=(age=16)), nobs);
+%PUT Class NLOBS: %smile_attrn(sashelp.class(WHERE=(age=16)), nlobs);
+%PUT Class NLOBSF: %smile_attrn(sashelp.class(WHERE=(age=16)), nlobsf);
+%PUT Class ANOBS(1): %smile_attrn(sashelp.class, ANOBS);
+%PUT Class ANOBS(2): %smile_attrn(sashelp.class(WHERE=(age=1)), ANOBS);
+%PUT Class NVARS: %smile_attrn(sashelp.class, NVARS);
+```
+
+
+
+
+**Log Output:**
+
+```
+Class NOBS(1): 19
+Class NOBS(2): 19
+Class NLOBS: 19
+Class NLOBSF: -1
+Class ANOBS(1): 1
+Class ANOBS(2): 1
+Class NVARS: 5
+```
+
+
+
+
+## Example 2 - error case examples
+
+
+```sas
+%PUT invalid data: %smile_attrn(sashelp.class2, nobs);
+%PUT invalid attribute: %smile_attrn(sashelp.class, dummy);
+```
+
+
+
+
+**Log Output:**
+
+```
+ERROR: SMILE_ATTRN - DATA (sashelp.class2) does not exist.
+invalid data: -1
+ERROR: SMILE_ATTRN - Invalid value for ATTRIB (dummy).
+invalid attribute: -1
+```
+
diff --git a/docs/test_smile_ods_document_flat_label.md b/docs/test_smile_ods_document_flat_label.md
index e73912c..f6b8477 100644
--- a/docs/test_smile_ods_document_flat_label.md
+++ b/docs/test_smile_ods_document_flat_label.md
@@ -1,456 +1,456 @@
-# TEST_SMILE_ODS_DOCUMENT_FLAT_LABEL
-
-Example program for macro calls of %smile_ods_document_flat_label
-
- - Author : Katja Glass
- - Creation : 2021-02-18
- - SAS Version: SAS 9.4
- - License : MIT
-
-
-Initialize macros
-
-```sas
-%LET root = ;
-OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
-```
-
-
-
-set options for nice layout
-
-```sas
-OPTIONS NODATE NONUMBER NOCENTER ORIENTATION=landscape;
-TITLE;FOOTNOTE;
-OPTIONS PS=35;
-```
-
-
-
-
-## Example 1 - empty ODS Document - warning expected
-
-
-```sas
-ODS DOCUMENT NAME = work.doc_empty (write);
-ODS DOCUMENT CLOSE;
-%smile_ods_document_flat_label(document=doc_empty);
-%PUT The warning message is expected;
-```
-
-
-
-
-**Log Output:**
-
-```
-WARNING: SMILE_ODS_DOCUMENT_FLAT_LABEL - DOCUMENT (doc_empty) does not contain any observations - no action done
-The warning message is expected
-```
-
-
-## Example 2 - not existing ODS Document - error expected
-
-
-```sas
-%smile_ods_document_flat_label(document=doc_notexist);
-%PUT The error message is expected;
-```
-
-
-
-
-**Log Output:**
-
-```
-ERROR: SMILE_ODS_DOCUMENT_FLAT_LABEL - DOCUMENT (doc_notexist) is no existing ODS DOCUMENT. Macro will abort
-The error message is expected
-```
-
-
-## Example 3 - create flat navigation PDF using one ODS DOCUMENT
-
-Comment:
-
-- the SAS TOC would be created a buggy linking (e.g. click "table 2" on TOC)
-- this had been reported to SAS(R)- it seems to be depending on viewer and whether the PDF is maximized or not
-- I am expecting no fix from SAS(R)
-
-
-
-include program to create one ODS document containing many reports
-
-```sas
-%INCLUDE "&root/programs/example_ods_document_many_reports.sas";
-```
-
-Create direct output without any modifications - ODS Structure for DOC_RESULTS contains several levels
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\Report#1 |Dir |Table 1: By Group Report about shoes
-\Report#1\ByGroup1#1 |Dir |Region=Canada
-\Report#1\ByGroup1#1\Report#1 |Table |
-\Report#1\ByGroup2#1 |Dir |Region=Pacific
-\Report#1\ByGroup2#1\Report#1 |Table |
-\Report#2 |Dir |Table 2: Table Class Output
-\Report#2\Report#1 |Table |
-\Report#3 |Dir |Table 3: Multiple outputs - Cars for make = Acura
-\Report#3\Report#1 |Table |
-\Report#4 |Dir |Table 4: Multiple outputs - Cars for make = Audi
-\Report#4\Report#1 |Table |
-\Report#5 |Dir |Table 5: Multiple outputs - Cars for make = BMW
-\Report#5\Report#1 |Table |
-\Report#6 |Dir |Table 6: Different label
-\Report#6\Report#1 |Table |
-\SGPlot#1 |Dir |Figure 1: Class graphic
-\SGPlot#1\SGPlot#1 |Graph |The SGPlot Procedure
-
-
-```sas
-ODS PDF FILE= "&root/results/ods_document_noflat1.pdf" nocontents;
-PROC DOCUMENT name=doc_results; replay; QUIT;
-ODS PDF CLOSE;
-```
-
-**Navigation contains two levels, e.g. BYLINE categories**
-![Screenshot](./img/screen_ods_doc_flat1.jpg)
-
-
-update the document to flatten labels
-
-```sas
-%smile_ods_document_flat_label(document=doc_results);
-```
-
-ODS Document structure is arranged flat by macro
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\all#1 |Table |Table 1: By Group Report about shoes
-\all#2 |Table |
-\all#3 |Table |Table 2: Table Class Output
-\all#4 |Table |Table 3: Multiple outputs - Cars for make = Acura
-\all#5 |Table |Table 4: Multiple outputs - Cars for make = Audi
-\all#6 |Table |Table 5: Multiple outputs - Cars for make = BMW
-\all#7 |Table |Table 6: Different label
-\all#8 |Graph |Figure 1: Class graphic
-
-Create PDF out of modified ODS Document
-
-```sas
-ODS PDF FILE= "&root/results/ods_document_flat1.pdf" nocontents;
-PROC DOCUMENT name=doc_results; replay; QUIT;
-ODS PDF CLOSE;
-```
-
-**Navigation contains one level**
-![Screenshot](./img/screen_ods_doc_flat2.jpg)
-
-
-The following source can be used to see the structure of the ODS DOCUMENT
-
-```sas
-ODS LISTING;
-PROC DOCUMENT NAME=doc_results(READ);
- LIST / levels=all details;
-RUN;
-ODS _ALL_ CLOSE;
-```
-
-
-
-
-
-
-## Example 4 - create flat navigation PDF using multiple ODS DOCUMENT - with re-labeling
-
-Comment:
-
-- a looping macro might be feasible for generic use
-- the SAS TOC is created and linking correctly
-- ODS PROCLABEL is ignored as the label is coming through the re-labeling
-
-
-include program to create one multiple ODS documents - one per report
-
-```sas
-%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
-```
-
-flat ODS Document structure per document, apply a specific label
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\Report#1 |Dir |Table 1: By Group Report about shoes
-\Report#1\ByGroup1#1 |Dir |Region=Canada
-\Report#1\ByGroup1#1\Report#1 |Table |
-\Report#1\ByGroup2#1 |Dir |Region=Pacific
-\Report#1\ByGroup2#1\Report#1 |Table |
-
-
-```sas
-%smile_ods_document_flat_label(document=doc_res1,label=Table 1);
-%smile_ods_document_flat_label(document=doc_res2,label=Table 2);
-%smile_ods_document_flat_label(document=doc_res3,label=Table 3);
-%smile_ods_document_flat_label(document=doc_res4,label=Table 4);
-%smile_ods_document_flat_label(document=doc_res5,label=Table 5);
-%smile_ods_document_flat_label(document=doc_res6,label=Table 6);
-%smile_ods_document_flat_label(document=doc_res_f1,label=Figure 1);
-```
-
-ODS Documents are flat now using a short label
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\all#1 |Table |Table 1
-\all#2 |Table |
-
-
-
-Create final PDF file
-
-```sas
-ODS PDF FILE= "&root/results/ods_document_flat2.pdf" CONTENTS;
-PROC DOCUMENT name=doc_res1; replay; QUIT;
-PROC DOCUMENT name=doc_res2; replay; QUIT;
-PROC DOCUMENT name=doc_res3; replay; QUIT;
-PROC DOCUMENT name=doc_res4; replay; QUIT;
-PROC DOCUMENT name=doc_res5; replay; QUIT;
-PROC DOCUMENT name=doc_res6; replay; QUIT;
-PROC DOCUMENT name=doc_res_f1; replay; QUIT;
-ODS PDF CLOSE;
-```
-
-Navigation and TOC contains one level with short bookmark labels, tables contain still full label
-** **
-
-**Bookmarks and TOC**
-
-![Screenshot](./img/screen_ods_doc_flat3.jpg)
-
-**First Table**
-
-![Screenshot](./img/screen_ods_doc_flat4.jpg)
-
-
-
-## Example 5 - create flat navigation PDF using multiple ODS DOCUMENT
-
-Comment:
-
-- a looping macro might be feasible for generic use
-- the SAS TOC is created and linking correctly
-
-
-include program to create one multiple ODS documents - one per report
-
-```sas
-%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
-```
-
-flat ODS Document structure per document, apply a specific label
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\Report#1 |Dir |Table 1: By Group Report about shoes
-\Report#1\ByGroup1#1 |Dir |Region=Canada
-\Report#1\ByGroup1#1\Report#1 |Table |
-\Report#1\ByGroup2#1 |Dir |Region=Pacific
-\Report#1\ByGroup2#1\Report#1 |Table |
-
-
-```sas
-%smile_ods_document_flat_label(document=doc_res1);
-%smile_ods_document_flat_label(document=doc_res2);
-%smile_ods_document_flat_label(document=doc_res3);
-%smile_ods_document_flat_label(document=doc_res4);
-%smile_ods_document_flat_label(document=doc_res5);
-%smile_ods_document_flat_label(document=doc_res6);
-%smile_ods_document_flat_label(document=doc_res_f1);
-```
-
-ODS Documents are flat now using the original TITLE label
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\all#1 |Table |Table 1: By Group Report about shoes
-\all#2 |Table |
-
-
-
-Create final PDF file
-
-```sas
-ODS PDF FILE= "&root/results/ods_document_flat3.pdf" CONTENTS;
-PROC DOCUMENT name=doc_res1; replay; QUIT;
-PROC DOCUMENT name=doc_res2; replay; QUIT;
-PROC DOCUMENT name=doc_res3; replay; QUIT;
-PROC DOCUMENT name=doc_res4; replay; QUIT;
-PROC DOCUMENT name=doc_res5; replay; QUIT;
-PROC DOCUMENT name=doc_res6; replay; QUIT;
-PROC DOCUMENT name=doc_res_f1; replay; QUIT;
-ODS PDF CLOSE;
-```
-
-**Navigation contains one level with original TITLE bookmark labels**
-![Screenshot](./img/screen_ods_doc_flat5.jpg)
-
-
-
-## Example 6 - create flat navigation PDF using multiple ODS DOCUMENT - no entry for some items
-
-Comment:
-
-- Table 1 and Table 3 have no label and no bookmark entry, but are included in the PDF
-- a looping macro might be feasible for generic use
-- the SAS TOC is created and linking correctly
-
-
-include program to create one multiple ODS documents - one per report
-
-```sas
-%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
-```
-
-flat ODS Document structure per document, some should not contain a label
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\Report#1 |Dir |Table 1: By Group Report about shoes
-\Report#1\ByGroup1#1 |Dir |Region=Canada
-\Report#1\ByGroup1#1\Report#1 |Table |
-\Report#1\ByGroup2#1 |Dir |Region=Pacific
-\Report#1\ByGroup2#1\Report#1 |Table |
-
-
-```sas
-%smile_ods_document_flat_label(document=doc_res1,label=,bookmarklabel=no);
-%smile_ods_document_flat_label(document=doc_res2);
-%smile_ods_document_flat_label(document=doc_res3,label=,bookmarklabel=no);
-%smile_ods_document_flat_label(document=doc_res4);
-```
-
-ODS Documents are flat now, some using no label
-
-
-ODS Path |ODS Type |Item Label
---- | --- | ---
-\all#1 |Table |
-\all#2 |Table |
-
-
-
-Create final PDF file
-
-```sas
-ODS PDF FILE= "&root/results/ods_document_flat4.pdf" CONTENTS;
-PROC DOCUMENT name=doc_res1; replay; QUIT;
-PROC DOCUMENT name=doc_res2; replay; QUIT;
-PROC DOCUMENT name=doc_res3; replay; QUIT;
-PROC DOCUMENT name=doc_res4; replay; QUIT;
-ODS PDF CLOSE;
-```
-
-Navigation and TOC for labeled entries, content of all is included in PDF
-** **
-
-**Bookmarks and TOC**
-
-![Screenshot](./img/screen_ods_doc_flat6.jpg)
-
-**Table 1 still in PDF**
-
-![Screenshot](./img/screen_ods_doc_flat7.jpg)
-
-
-
-## Example 7 - create flat navigation PDF using multiple ODS DOCUMENTS with custom TOC
-
-Comment:
-
-- Table 1 and Table 3 have no label and no bookmark entry, but are included in the PDF
-- a looping macro might be feasible for generic use
-- the SAS TOC is created and linking correctly
-
-
-create ODS Documents and flat them
-
-```sas
-%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
-%smile_ods_document_flat_label(document=doc_res1);
-%smile_ods_document_flat_label(document=doc_res2);
-%smile_ods_document_flat_label(document=doc_res3);
-%smile_ods_document_flat_label(document=doc_res4);
-```
-
-
-
-store the final PDF document with REPLAY options
-
-```sas
-ODS PDF FILE= "&root/results/ods_document_flat5_custom_toc.pdf" NOCONTENTS BOOKMARKGEN;
-```
-
-
-
-include a custom TOC, but without an anchor
-
-```sas
-PROC DOCUMENT name=doc_toc; replay; QUIT;
-```
-
-
-
-include tables with anchor
-
-```sas
-ODS PDF ANCHOR = 'table1_x1';
-PROC DOCUMENT name=doc_res1; replay; QUIT;
-ODS PDF ANCHOR = 'table2_x1';
-PROC DOCUMENT name=doc_res2; replay; QUIT;
-ODS PDF ANCHOR = 'table3_x1';
-PROC DOCUMENT name=doc_res3; replay; QUIT;
-ODS PDF ANCHOR = 'table4_x1';
-PROC DOCUMENT name=doc_res4; replay; QUIT;
-ODS PDF CLOSE;
-```
-
-
-
-**Custom TOC and flat bookmarks are available**
-![Screenshot](./img/screen_ods_doc_flat8.jpg)
-
-
-
-## Example 8 - create flat navigation PDF using multiple ODS DOCUMENTS - many outputs
-
-
-
-create 100 ODS Documents, flat them and create the output in PDF
-
-```sas
-%INCLUDE "&root/programs/example_ods_document_single_reports_big.sas";
-%MACRO do_it();
- %LOCAL i;
- %DO i = 1 %TO 100;
- %smile_ods_document_flat_label(document=doc_res&i);
- %END;
- ODS PDF FILE= "&root/results/ods_document_flat6_big.pdf" CONTENTS;
- %DO i = 1 %TO 100;
- PROC DOCUMENT name=doc_res&i; replay; QUIT;
- %END;
- ODS PDF CLOSE;
-%MEND;
-%do_it();
-```
-
-**Flat bookmarks are available**
-![Screenshot](./img/screen_ods_doc_flat9.jpg)
+# TEST_SMILE_ODS_DOCUMENT_FLAT_LABEL
+
+Example program for macro calls of %smile_ods_document_flat_label
+
+ - Author : Katja Glass
+ - Creation : 2021-02-18
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+Initialize macros
+
+```sas
+%LET root = ;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+```
+
+
+
+set options for nice layout
+
+```sas
+OPTIONS NODATE NONUMBER NOCENTER ORIENTATION=landscape;
+TITLE;FOOTNOTE;
+OPTIONS PS=35;
+```
+
+
+
+
+## Example 1 - empty ODS Document - warning expected
+
+
+```sas
+ODS DOCUMENT NAME = work.doc_empty (write);
+ODS DOCUMENT CLOSE;
+%smile_ods_document_flat_label(document=doc_empty);
+%PUT The warning message is expected;
+```
+
+
+
+
+**Log Output:**
+
+```
+WARNING: SMILE_ODS_DOCUMENT_FLAT_LABEL - DOCUMENT (doc_empty) does not contain any observations - no action done
+The warning message is expected
+```
+
+
+## Example 2 - not existing ODS Document - error expected
+
+
+```sas
+%smile_ods_document_flat_label(document=doc_notexist);
+%PUT The error message is expected;
+```
+
+
+
+
+**Log Output:**
+
+```
+ERROR: SMILE_ODS_DOCUMENT_FLAT_LABEL - DOCUMENT (doc_notexist) is no existing ODS DOCUMENT. Macro will abort
+The error message is expected
+```
+
+
+## Example 3 - create flat navigation PDF using one ODS DOCUMENT
+
+Comment:
+
+- the SAS TOC would be created a buggy linking (e.g. click "table 2" on TOC)
+- this had been reported to SAS(R)- it seems to be depending on viewer and whether the PDF is maximized or not
+- I am expecting no fix from SAS(R)
+
+
+
+include program to create one ODS document containing many reports
+
+```sas
+%INCLUDE "&root/programs/example_ods_document_many_reports.sas";
+```
+
+Create direct output without any modifications - ODS Structure for DOC_RESULTS contains several levels
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\Report#1 |Dir |Table 1: By Group Report about shoes
+\Report#1\ByGroup1#1 |Dir |Region=Canada
+\Report#1\ByGroup1#1\Report#1 |Table |
+\Report#1\ByGroup2#1 |Dir |Region=Pacific
+\Report#1\ByGroup2#1\Report#1 |Table |
+\Report#2 |Dir |Table 2: Table Class Output
+\Report#2\Report#1 |Table |
+\Report#3 |Dir |Table 3: Multiple outputs - Cars for make = Acura
+\Report#3\Report#1 |Table |
+\Report#4 |Dir |Table 4: Multiple outputs - Cars for make = Audi
+\Report#4\Report#1 |Table |
+\Report#5 |Dir |Table 5: Multiple outputs - Cars for make = BMW
+\Report#5\Report#1 |Table |
+\Report#6 |Dir |Table 6: Different label
+\Report#6\Report#1 |Table |
+\SGPlot#1 |Dir |Figure 1: Class graphic
+\SGPlot#1\SGPlot#1 |Graph |The SGPlot Procedure
+
+
+```sas
+ODS PDF FILE= "&root/results/ods_document_noflat1.pdf" nocontents;
+PROC DOCUMENT name=doc_results; replay; QUIT;
+ODS PDF CLOSE;
+```
+
+**Navigation contains two levels, e.g. BYLINE categories**
+![Screenshot](./img/screen_ods_doc_flat1.jpg)
+
+
+update the document to flatten labels
+
+```sas
+%smile_ods_document_flat_label(document=doc_results);
+```
+
+ODS Document structure is arranged flat by macro
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\all#1 |Table |Table 1: By Group Report about shoes
+\all#2 |Table |
+\all#3 |Table |Table 2: Table Class Output
+\all#4 |Table |Table 3: Multiple outputs - Cars for make = Acura
+\all#5 |Table |Table 4: Multiple outputs - Cars for make = Audi
+\all#6 |Table |Table 5: Multiple outputs - Cars for make = BMW
+\all#7 |Table |Table 6: Different label
+\all#8 |Graph |Figure 1: Class graphic
+
+Create PDF out of modified ODS Document
+
+```sas
+ODS PDF FILE= "&root/results/ods_document_flat1.pdf" nocontents;
+PROC DOCUMENT name=doc_results; replay; QUIT;
+ODS PDF CLOSE;
+```
+
+**Navigation contains one level**
+![Screenshot](./img/screen_ods_doc_flat2.jpg)
+
+
+The following source can be used to see the structure of the ODS DOCUMENT
+
+```sas
+ODS LISTING;
+PROC DOCUMENT NAME=doc_results(READ);
+ LIST / levels=all details;
+RUN;
+ODS _ALL_ CLOSE;
+```
+
+
+
+
+
+
+## Example 4 - create flat navigation PDF using multiple ODS DOCUMENT - with re-labeling
+
+Comment:
+
+- a looping macro might be feasible for generic use
+- the SAS TOC is created and linking correctly
+- ODS PROCLABEL is ignored as the label is coming through the re-labeling
+
+
+include program to create one multiple ODS documents - one per report
+
+```sas
+%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
+```
+
+flat ODS Document structure per document, apply a specific label
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\Report#1 |Dir |Table 1: By Group Report about shoes
+\Report#1\ByGroup1#1 |Dir |Region=Canada
+\Report#1\ByGroup1#1\Report#1 |Table |
+\Report#1\ByGroup2#1 |Dir |Region=Pacific
+\Report#1\ByGroup2#1\Report#1 |Table |
+
+
+```sas
+%smile_ods_document_flat_label(document=doc_res1,label=Table 1);
+%smile_ods_document_flat_label(document=doc_res2,label=Table 2);
+%smile_ods_document_flat_label(document=doc_res3,label=Table 3);
+%smile_ods_document_flat_label(document=doc_res4,label=Table 4);
+%smile_ods_document_flat_label(document=doc_res5,label=Table 5);
+%smile_ods_document_flat_label(document=doc_res6,label=Table 6);
+%smile_ods_document_flat_label(document=doc_res_f1,label=Figure 1);
+```
+
+ODS Documents are flat now using a short label
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\all#1 |Table |Table 1
+\all#2 |Table |
+
+
+
+Create final PDF file
+
+```sas
+ODS PDF FILE= "&root/results/ods_document_flat2.pdf" CONTENTS;
+PROC DOCUMENT name=doc_res1; replay; QUIT;
+PROC DOCUMENT name=doc_res2; replay; QUIT;
+PROC DOCUMENT name=doc_res3; replay; QUIT;
+PROC DOCUMENT name=doc_res4; replay; QUIT;
+PROC DOCUMENT name=doc_res5; replay; QUIT;
+PROC DOCUMENT name=doc_res6; replay; QUIT;
+PROC DOCUMENT name=doc_res_f1; replay; QUIT;
+ODS PDF CLOSE;
+```
+
+Navigation and TOC contains one level with short bookmark labels, tables contain still full label
+** **
+
+**Bookmarks and TOC**
+
+![Screenshot](./img/screen_ods_doc_flat3.jpg)
+
+**First Table**
+
+![Screenshot](./img/screen_ods_doc_flat4.jpg)
+
+
+
+## Example 5 - create flat navigation PDF using multiple ODS DOCUMENT
+
+Comment:
+
+- a looping macro might be feasible for generic use
+- the SAS TOC is created and linking correctly
+
+
+include program to create one multiple ODS documents - one per report
+
+```sas
+%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
+```
+
+flat ODS Document structure per document, apply a specific label
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\Report#1 |Dir |Table 1: By Group Report about shoes
+\Report#1\ByGroup1#1 |Dir |Region=Canada
+\Report#1\ByGroup1#1\Report#1 |Table |
+\Report#1\ByGroup2#1 |Dir |Region=Pacific
+\Report#1\ByGroup2#1\Report#1 |Table |
+
+
+```sas
+%smile_ods_document_flat_label(document=doc_res1);
+%smile_ods_document_flat_label(document=doc_res2);
+%smile_ods_document_flat_label(document=doc_res3);
+%smile_ods_document_flat_label(document=doc_res4);
+%smile_ods_document_flat_label(document=doc_res5);
+%smile_ods_document_flat_label(document=doc_res6);
+%smile_ods_document_flat_label(document=doc_res_f1);
+```
+
+ODS Documents are flat now using the original TITLE label
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\all#1 |Table |Table 1: By Group Report about shoes
+\all#2 |Table |
+
+
+
+Create final PDF file
+
+```sas
+ODS PDF FILE= "&root/results/ods_document_flat3.pdf" CONTENTS;
+PROC DOCUMENT name=doc_res1; replay; QUIT;
+PROC DOCUMENT name=doc_res2; replay; QUIT;
+PROC DOCUMENT name=doc_res3; replay; QUIT;
+PROC DOCUMENT name=doc_res4; replay; QUIT;
+PROC DOCUMENT name=doc_res5; replay; QUIT;
+PROC DOCUMENT name=doc_res6; replay; QUIT;
+PROC DOCUMENT name=doc_res_f1; replay; QUIT;
+ODS PDF CLOSE;
+```
+
+**Navigation contains one level with original TITLE bookmark labels**
+![Screenshot](./img/screen_ods_doc_flat5.jpg)
+
+
+
+## Example 6 - create flat navigation PDF using multiple ODS DOCUMENT - no entry for some items
+
+Comment:
+
+- Table 1 and Table 3 have no label and no bookmark entry, but are included in the PDF
+- a looping macro might be feasible for generic use
+- the SAS TOC is created and linking correctly
+
+
+include program to create one multiple ODS documents - one per report
+
+```sas
+%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
+```
+
+flat ODS Document structure per document, some should not contain a label
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\Report#1 |Dir |Table 1: By Group Report about shoes
+\Report#1\ByGroup1#1 |Dir |Region=Canada
+\Report#1\ByGroup1#1\Report#1 |Table |
+\Report#1\ByGroup2#1 |Dir |Region=Pacific
+\Report#1\ByGroup2#1\Report#1 |Table |
+
+
+```sas
+%smile_ods_document_flat_label(document=doc_res1,label=,bookmarklabel=no);
+%smile_ods_document_flat_label(document=doc_res2);
+%smile_ods_document_flat_label(document=doc_res3,label=,bookmarklabel=no);
+%smile_ods_document_flat_label(document=doc_res4);
+```
+
+ODS Documents are flat now, some using no label
+
+
+ODS Path |ODS Type |Item Label
+--- | --- | ---
+\all#1 |Table |
+\all#2 |Table |
+
+
+
+Create final PDF file
+
+```sas
+ODS PDF FILE= "&root/results/ods_document_flat4.pdf" CONTENTS;
+PROC DOCUMENT name=doc_res1; replay; QUIT;
+PROC DOCUMENT name=doc_res2; replay; QUIT;
+PROC DOCUMENT name=doc_res3; replay; QUIT;
+PROC DOCUMENT name=doc_res4; replay; QUIT;
+ODS PDF CLOSE;
+```
+
+Navigation and TOC for labeled entries, content of all is included in PDF
+** **
+
+**Bookmarks and TOC**
+
+![Screenshot](./img/screen_ods_doc_flat6.jpg)
+
+**Table 1 still in PDF**
+
+![Screenshot](./img/screen_ods_doc_flat7.jpg)
+
+
+
+## Example 7 - create flat navigation PDF using multiple ODS DOCUMENTS with custom TOC
+
+Comment:
+
+- Table 1 and Table 3 have no label and no bookmark entry, but are included in the PDF
+- a looping macro might be feasible for generic use
+- the SAS TOC is created and linking correctly
+
+
+create ODS Documents and flat them
+
+```sas
+%INCLUDE "&root/programs/example_ods_document_single_reports.sas";
+%smile_ods_document_flat_label(document=doc_res1);
+%smile_ods_document_flat_label(document=doc_res2);
+%smile_ods_document_flat_label(document=doc_res3);
+%smile_ods_document_flat_label(document=doc_res4);
+```
+
+
+
+store the final PDF document with REPLAY options
+
+```sas
+ODS PDF FILE= "&root/results/ods_document_flat5_custom_toc.pdf" NOCONTENTS BOOKMARKGEN;
+```
+
+
+
+include a custom TOC, but without an anchor
+
+```sas
+PROC DOCUMENT name=doc_toc; replay; QUIT;
+```
+
+
+
+include tables with anchor
+
+```sas
+ODS PDF ANCHOR = 'table1_x1';
+PROC DOCUMENT name=doc_res1; replay; QUIT;
+ODS PDF ANCHOR = 'table2_x1';
+PROC DOCUMENT name=doc_res2; replay; QUIT;
+ODS PDF ANCHOR = 'table3_x1';
+PROC DOCUMENT name=doc_res3; replay; QUIT;
+ODS PDF ANCHOR = 'table4_x1';
+PROC DOCUMENT name=doc_res4; replay; QUIT;
+ODS PDF CLOSE;
+```
+
+
+
+**Custom TOC and flat bookmarks are available**
+![Screenshot](./img/screen_ods_doc_flat8.jpg)
+
+
+
+## Example 8 - create flat navigation PDF using multiple ODS DOCUMENTS - many outputs
+
+
+
+create 100 ODS Documents, flat them and create the output in PDF
+
+```sas
+%INCLUDE "&root/programs/example_ods_document_single_reports_big.sas";
+%MACRO do_it();
+ %LOCAL i;
+ %DO i = 1 %TO 100;
+ %smile_ods_document_flat_label(document=doc_res&i);
+ %END;
+ ODS PDF FILE= "&root/results/ods_document_flat6_big.pdf" CONTENTS;
+ %DO i = 1 %TO 100;
+ PROC DOCUMENT name=doc_res&i; replay; QUIT;
+ %END;
+ ODS PDF CLOSE;
+%MEND;
+%do_it();
+```
+
+**Flat bookmarks are available**
+![Screenshot](./img/screen_ods_doc_flat9.jpg)
diff --git a/docs/test_smile_pdf_merge.md b/docs/test_smile_pdf_merge.md
index eb6fcb9..32c0e61 100644
--- a/docs/test_smile_pdf_merge.md
+++ b/docs/test_smile_pdf_merge.md
@@ -1,162 +1,162 @@
-# TEST_SMILE_PDF_MERGE
-
-Example program for macro calls of %smile_pdf_merge
-
- - Author : Katja Glass
- - Creation : 2021-02-18
- - SAS Version: SAS 9.4
- - License : MIT
-
-
-Initialize macros and variables
-
-```sas
-%LET root = ;
-%LET out = &root/results;
-%LET libPath = &root/lib;
-```
-
-
-
-
-```sas
-OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
-```
-
-
-
-Create four PDF files which should be merged
-
-```sas
-%INCLUDE "&root/programs/example_pdf_merge_create_single_pdfs.sas";
-```
-
-
-
-
-## Example 1 - Merge PDF Documents - Create long titles
-
-
-
-Create the content dataset to specify files and bookmark labels
-
-```sas
-DATA content;
- ATTRIB inFile FORMAT=$255.;
- ATTRIB bookmark FORMAT=$255.;
- inFile = "&out/input_pdf_merge_1.pdf";
- bookmark = "Table 1: By Group Report about shoes";
- OUTPUT;
- inFile = "&out/input_pdf_merge_2.pdf";
- bookmark = "Table 2: Multiple outputs - Cars for make = Acura";
- OUTPUT;
- inFile = "&out/input_pdf_merge_3.pdf";
- bookmark = "Table 3: Multiple outputs - Cars for make = Audi";
- OUTPUT;
- inFile = "&out/input_pdf_merge_4.pdf";
- bookmark = "Table 4: Multiple outputs - Cars for make = BMW";
- OUTPUT;
-RUN;
-```
-
-
-
-CONTENT dataset created
-
-
-INFILE |BOOKMARK
---- | ---
-<path>/results/input_pdf_merge_1.pdf |Table 1: By Group Report about shoes
-<path>/results/input_pdf_merge_2.pdf |Table 2: Multiple outputs - Cars for make = Acura
-<path>/results/input_pdf_merge_3.pdf |Table 3: Multiple outputs - Cars for make = Audi
-<path>/results/input_pdf_merge_4.pdf |Table 4: Multiple outputs - Cars for make = BMW
-
-
-
-Call macro to merge documents, additionally store GROOVY program
-
-```sas
-%smile_pdf_merge(
- data = content
- , outfile = &out/pdf_merge_output1.pdf
- , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
- , sourcefile = &out/pdf_merge_program1.sas
- , run_groovy = YES
-);
-```
-
-
-
-**Desired PDF file has been created**
-![Screenshot](./img/screen_pdf_merge1.jpg)
-
-
-
-## Example 2 - Merge PDF Documents - Create short titles
-
-
-
-Create the content dataset to specify files and bookmark labels
-
-```sas
-DATA content2;
- ATTRIB inFile FORMAT=$255.;
- ATTRIB bookmark FORMAT=$255.;
- inFile = "&out/input_pdf_merge_1.pdf"; bookmark = "Table 1"; OUTPUT;
- inFile = "&out/input_pdf_merge_2.pdf"; bookmark = "Table 2"; OUTPUT;
- inFile = "&out/input_pdf_merge_3.pdf"; bookmark = "Table 3"; OUTPUT;
- inFile = "&out/input_pdf_merge_4.pdf"; bookmark = "Table 4"; OUTPUT;
-RUN;
-```
-
-
-
-CONTENT dataset created
-
-
-INFILE |BOOKMARK
---- | ---
-<path>/results/input_pdf_merge_1.pdf |Table 1: By Group Report about shoes
-<path>/results/input_pdf_merge_2.pdf |Table 2: Multiple outputs - Cars for make = Acura
-<path>/results/input_pdf_merge_3.pdf |Table 3: Multiple outputs - Cars for make = Audi
-<path>/results/input_pdf_merge_4.pdf |Table 4: Multiple outputs - Cars for make = BMW
-
-
-
-Call macro to merge documents
-
-```sas
-%smile_pdf_merge(
- data = content2
- , outfile = &out/pdf_merge_output2.pdf
- , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
- , sourcefile = &out/pdf_merge_program2.sas
- , run_groovy = YES
-);
-```
-
-
-
-**Desired PDF file has been created**
-![Screenshot](./img/screen_pdf_merge2.jpg)
-
-
-
-## Example 3 - Merge PDF Documents - Do not store GROOVY program
-
-
-
-Call macro to merge documents, do not store GROOVY program
-
-```sas
-%smile_pdf_merge(
- data = content2
- , outfile = &out/pdf_merge_output2.pdf
- , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
-);
-```
-
-
-
-**Desired PDF file has been created**
-![Screenshot](./img/screen_pdf_merge2.jpg)
+# TEST_SMILE_PDF_MERGE
+
+Example program for macro calls of %smile_pdf_merge
+
+ - Author : Katja Glass
+ - Creation : 2021-02-18
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+Initialize macros and variables
+
+```sas
+%LET root = ;
+%LET out = &root/results;
+%LET libPath = &root/lib;
+```
+
+
+
+
+```sas
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+```
+
+
+
+Create four PDF files which should be merged
+
+```sas
+%INCLUDE "&root/programs/example_pdf_merge_create_single_pdfs.sas";
+```
+
+
+
+
+## Example 1 - Merge PDF Documents - Create long titles
+
+
+
+Create the content dataset to specify files and bookmark labels
+
+```sas
+DATA content;
+ ATTRIB inFile FORMAT=$255.;
+ ATTRIB bookmark FORMAT=$255.;
+ inFile = "&out/input_pdf_merge_1.pdf";
+ bookmark = "Table 1: By Group Report about shoes";
+ OUTPUT;
+ inFile = "&out/input_pdf_merge_2.pdf";
+ bookmark = "Table 2: Multiple outputs - Cars for make = Acura";
+ OUTPUT;
+ inFile = "&out/input_pdf_merge_3.pdf";
+ bookmark = "Table 3: Multiple outputs - Cars for make = Audi";
+ OUTPUT;
+ inFile = "&out/input_pdf_merge_4.pdf";
+ bookmark = "Table 4: Multiple outputs - Cars for make = BMW";
+ OUTPUT;
+RUN;
+```
+
+
+
+CONTENT dataset created
+
+
+INFILE |BOOKMARK
+--- | ---
+<path>/results/input_pdf_merge_1.pdf |Table 1: By Group Report about shoes
+<path>/results/input_pdf_merge_2.pdf |Table 2: Multiple outputs - Cars for make = Acura
+<path>/results/input_pdf_merge_3.pdf |Table 3: Multiple outputs - Cars for make = Audi
+<path>/results/input_pdf_merge_4.pdf |Table 4: Multiple outputs - Cars for make = BMW
+
+
+
+Call macro to merge documents, additionally store GROOVY program
+
+```sas
+%smile_pdf_merge(
+ data = content
+ , outfile = &out/pdf_merge_output1.pdf
+ , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
+ , sourcefile = &out/pdf_merge_program1.sas
+ , run_groovy = YES
+);
+```
+
+
+
+**Desired PDF file has been created**
+![Screenshot](./img/screen_pdf_merge1.jpg)
+
+
+
+## Example 2 - Merge PDF Documents - Create short titles
+
+
+
+Create the content dataset to specify files and bookmark labels
+
+```sas
+DATA content2;
+ ATTRIB inFile FORMAT=$255.;
+ ATTRIB bookmark FORMAT=$255.;
+ inFile = "&out/input_pdf_merge_1.pdf"; bookmark = "Table 1"; OUTPUT;
+ inFile = "&out/input_pdf_merge_2.pdf"; bookmark = "Table 2"; OUTPUT;
+ inFile = "&out/input_pdf_merge_3.pdf"; bookmark = "Table 3"; OUTPUT;
+ inFile = "&out/input_pdf_merge_4.pdf"; bookmark = "Table 4"; OUTPUT;
+RUN;
+```
+
+
+
+CONTENT dataset created
+
+
+INFILE |BOOKMARK
+--- | ---
+<path>/results/input_pdf_merge_1.pdf |Table 1: By Group Report about shoes
+<path>/results/input_pdf_merge_2.pdf |Table 2: Multiple outputs - Cars for make = Acura
+<path>/results/input_pdf_merge_3.pdf |Table 3: Multiple outputs - Cars for make = Audi
+<path>/results/input_pdf_merge_4.pdf |Table 4: Multiple outputs - Cars for make = BMW
+
+
+
+Call macro to merge documents
+
+```sas
+%smile_pdf_merge(
+ data = content2
+ , outfile = &out/pdf_merge_output2.pdf
+ , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
+ , sourcefile = &out/pdf_merge_program2.sas
+ , run_groovy = YES
+);
+```
+
+
+
+**Desired PDF file has been created**
+![Screenshot](./img/screen_pdf_merge2.jpg)
+
+
+
+## Example 3 - Merge PDF Documents - Do not store GROOVY program
+
+
+
+Call macro to merge documents, do not store GROOVY program
+
+```sas
+%smile_pdf_merge(
+ data = content2
+ , outfile = &out/pdf_merge_output2.pdf
+ , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
+);
+```
+
+
+
+**Desired PDF file has been created**
+![Screenshot](./img/screen_pdf_merge2.jpg)
diff --git a/docs/test_smile_pdf_read_bookmarks.md b/docs/test_smile_pdf_read_bookmarks.md
index 4c76420..91e3c88 100644
--- a/docs/test_smile_pdf_read_bookmarks.md
+++ b/docs/test_smile_pdf_read_bookmarks.md
@@ -1,80 +1,80 @@
-# TEST_SMILE_PDF_READ_BOOKMARKS
-
-Example program for macro calls of %smile_pdf_read_bookmarks
-
- - Author : Katja Glass
- - Creation : 2021-02-18
- - SAS Version: SAS 9.4
- - License : MIT
-
-
-Initialize macros
-
-```sas
-%LET root = ;
-OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
-```
-
-
-
-
-## Example 1 - Read bookmarks from a document containing one bookmark level
-
-
-
-
-```sas
-%smile_pdf_read_bookmarks(pdfFile = &root/results/ods_document_flat1.pdf,
- outdat = book_flat1,
- pdfbox_jar_path = &root/lib/pdfbox-app-2.0.22.jar);
-```
-
-
-
-Bookmarks and levels are stored in BOOK_FLAT1
-
-
-LEVEL |TITLE |PAGE
---- | --- | ---
-1 |Table 1: By Group Report about shoes |1
-1 |Table 2: Table Class Output |5
-1 |Table 3: Multiple outputs - Cars for make = Acura |6
-1 |Table 4: Multiple outputs - Cars for make = Audi |7
-1 |Table 5: Multiple outputs - Cars for make = BMW |8
-1 |Table 6: Different label |9
-1 |Figure 1: Class graphic |10
-
-
-
-
-
-
-## Example 2 - Read bookmarks from a document containing several bookmark levels
-
-
-
-
-```sas
-%smile_pdf_read_bookmarks(pdfFile = &root/results/ods_document_noflat1.pdf,
- outdat = book_noflat1,
- pdfbox_jar_path = &root/lib/pdfbox-app-2.0.22.jar);
-```
-
-
-
-Bookmarks and levels are stored in BOOK_NOFLAT1
-
-
-LEVEL |TITLE |PAGE
---- | --- | ---
-1 |Table 1: By Group Report about shoes |1
-2 |Region=Canada |1
-2 |Region=Pacific |3
-1 |Table 2: Table Class Output |5
-1 |Table 3: Multiple outputs - Cars for make = Acura |6
-1 |Table 4: Multiple outputs - Cars for make = Audi |7
-1 |Table 5: Multiple outputs - Cars for make = BMW |8
-1 |Table 6: Different label |9
-1 |Figure 1: Class graphic |10
-2 |The SGPlot Procedure |10
-
+# TEST_SMILE_PDF_READ_BOOKMARKS
+
+Example program for macro calls of %smile_pdf_read_bookmarks
+
+ - Author : Katja Glass
+ - Creation : 2021-02-18
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+Initialize macros
+
+```sas
+%LET root = ;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+```
+
+
+
+
+## Example 1 - Read bookmarks from a document containing one bookmark level
+
+
+
+
+```sas
+%smile_pdf_read_bookmarks(pdfFile = &root/results/ods_document_flat1.pdf,
+ outdat = book_flat1,
+ pdfbox_jar_path = &root/lib/pdfbox-app-2.0.22.jar);
+```
+
+
+
+Bookmarks and levels are stored in BOOK_FLAT1
+
+
+LEVEL |TITLE |PAGE
+--- | --- | ---
+1 |Table 1: By Group Report about shoes |1
+1 |Table 2: Table Class Output |5
+1 |Table 3: Multiple outputs - Cars for make = Acura |6
+1 |Table 4: Multiple outputs - Cars for make = Audi |7
+1 |Table 5: Multiple outputs - Cars for make = BMW |8
+1 |Table 6: Different label |9
+1 |Figure 1: Class graphic |10
+
+
+
+
+
+
+## Example 2 - Read bookmarks from a document containing several bookmark levels
+
+
+
+
+```sas
+%smile_pdf_read_bookmarks(pdfFile = &root/results/ods_document_noflat1.pdf,
+ outdat = book_noflat1,
+ pdfbox_jar_path = &root/lib/pdfbox-app-2.0.22.jar);
+```
+
+
+
+Bookmarks and levels are stored in BOOK_NOFLAT1
+
+
+LEVEL |TITLE |PAGE
+--- | --- | ---
+1 |Table 1: By Group Report about shoes |1
+2 |Region=Canada |1
+2 |Region=Pacific |3
+1 |Table 2: Table Class Output |5
+1 |Table 3: Multiple outputs - Cars for make = Acura |6
+1 |Table 4: Multiple outputs - Cars for make = Audi |7
+1 |Table 5: Multiple outputs - Cars for make = BMW |8
+1 |Table 6: Different label |9
+1 |Figure 1: Class graphic |10
+2 |The SGPlot Procedure |10
+
diff --git a/docs/test_smile_replace_in_text_files.md b/docs/test_smile_replace_in_text_files.md
new file mode 100644
index 0000000..f6a21ba
--- /dev/null
+++ b/docs/test_smile_replace_in_text_files.md
@@ -0,0 +1,165 @@
+# TEST_SMILE_REPLACE_IN_TEXT_FILES
+
+Example program for macro calls of %smile_replace_in_text_files
+
+ - Author : Katja Glass
+ - Creation : 2021-02-15
+ - SAS Version: SAS 9.4
+ - License : MIT
+
+
+initialize macros
+
+```sas
+%LET root = ;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+OPTIONS NONOTES;
+```
+
+
+
+support macro to create a text file
+
+```sas
+%MACRO create_text_file();
+ DATA _NULL_;
+ FILE "&root/results/temp/example.sas";
+ PUT "* This is a file created by a program to demonstrate text replacements";
+ PUT "* Created: {todayDate}";
+ PUT '%LET path = ;';
+ RUN;
+%MEND;
+```
+
+
+
+support macro to print content of text file
+
+```sas
+%MACRO print_text_file();
+ DATA _NULL_;
+ INFILE "&root/results/temp/example.sas";
+ INPUT;
+ PUT _INFILE_;
+ RUN;
+%MEND;
+```
+
+
+
+
+## Example 1 - replace in all sas files
+
+
+
+create a sas file
+
+```sas
+%create_text_file();
+```
+
+
+
+file has been created with the following content
+
+```sas
+%print_text_file();
+```
+
+
+
+
+**Log Output:**
+
+```
+* This is a file created by a program to demonstrate text replacements
+* Created: {todayDate}
+%LET path = ;
+```
+
+call macro to replace in all sas files
+
+```sas
+%smile_replace_in_text_files(
+ inpath = &root/results/temp,
+ outpath = &root/results/temp,
+ replace_from = '',
+ replace_to = 'c:\temp\myPath');
+```
+
+
+
+file contains the new text
+
+```sas
+%print_text_file();
+```
+
+
+
+
+**Log Output:**
+
+```
+* This is a file created by a program to demonstrate text replacements
+* Created: {todayDate}
+%LET path = c:\temp\myPath;
+```
+
+
+## Example 2 - replace {todayDate} in all sas files
+
+
+
+create a sas file
+
+```sas
+%create_text_file();
+```
+
+
+
+file has been created with the following content
+
+```sas
+%print_text_file();
+```
+
+
+
+
+**Log Output:**
+
+```
+* This is a file created by a program to demonstrate text replacements
+* Created: {todayDate}
+%LET path = ;
+```
+
+call macro to replace in all sas files
+
+```sas
+%smile_replace_in_text_files(
+ inpath = &root/results/temp,
+ outpath = &root/results/temp,
+ replace_from = '{todayDate}',
+ replace_to = "%SYSFUNC(date(),date9.)");
+```
+
+
+
+file contains the current date
+
+```sas
+%print_text_file();
+```
+
+
+**Log Output:**
+
+```
+* This is a file created by a program to demonstrate text replacements
+* Created: 05MAR2021
+%LET path = ;
+```
+
diff --git a/macros/smile_attr_var.sas b/macros/smile_attr_var.sas
index d2ca187..b36cf69 100644
--- a/macros/smile_attr_var.sas
+++ b/macros/smile_attr_var.sas
@@ -1,70 +1,70 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_attr_var
-%* Parameters : DATA - name of the SAS dataset
-%* VAR - name of variable
-%* ATTRIB - SAS variable attrib keyword (e.g. VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT)
-%*
-%* Purpose : Function-style macro to return a variable attribute of a dataset. The following attributes are available:
-%* VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT
-%*
-%* ExampleProg: ../programs/test_smile_attr_var.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-02-19
-%* License : MIT
-%*
-%* Reference : Main programming parts are coming from attrv.sas macro from Roland Rashleigh-Berry who
-%* has published his code under the unlicence license in his utility package
-%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-%PUT VARTYPE for name: %smile_attr_var(sashelp.class, name, vartype);
-%PUT VARTYPE for age: %smile_attr_var(sashelp.class, age, vartype);
-%PUT VARLABEL for name: %smile_attr_var(sashelp.class, name, varlabel);
-%PUT VARLEN for name: %smile_attr_var(sashelp.class, name, varlen);
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_attr_var(data, var, attrib);
- %LOCAL dsid rc macro varnum;
-
- %LET macro = &sysmacroname;
-
- %* check: ATTRIB must contain valid options;
- %IF %UPCASE(&attrib) NE VARTYPE AND
- %UPCASE(&attrib) NE VARLEN AND
- %UPCASE(&attrib) NE VARLABEL AND
- %UPCASE(&attrib) NE VARFMT AND
- %UPCASE(&attrib) NE VARINFMT
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib) - only the following are supported:;
- %PUT ¯o - VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT;
- -1
- %RETURN;
- %END;
-
- %* perform action and put value for processing;
- %LET dsid=%SYSFUNC(OPEN(&data,is));
-
- %IF &dsid EQ 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
- -1
- %END;
- %ELSE %DO;
- %LET varnum = %SYSFUNC(VARNUM(&dsid,&var));
- %IF &varnum LT 1
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - Variable VAR (&var) does not exist in DATA (&data).;
- -1
- %RETURN;
- %END;
- %SYSFUNC(&attrib(&dsid,&varnum))
- %LET rc=%SYSFUNC(CLOSE(&dsid));
- %END;
-%MEND smile_attr_var;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_attr_var
+%* Parameters : DATA - name of the SAS dataset
+%* VAR - name of variable
+%* ATTRIB - SAS variable attrib keyword (e.g. VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT)
+%*
+%* Purpose : Function-style macro to return a variable attribute of a dataset. The following attributes are available:
+%* VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT
+%*
+%* ExampleProg: ../programs/test_smile_attr_var.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : Main programming parts are coming from attrv.sas macro from Roland Rashleigh-Berry who
+%* has published his code under the unlicence license in his utility package
+%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%PUT VARTYPE for name: %smile_attr_var(sashelp.class, name, vartype);
+%PUT VARTYPE for age: %smile_attr_var(sashelp.class, age, vartype);
+%PUT VARLABEL for name: %smile_attr_var(sashelp.class, name, varlabel);
+%PUT VARLEN for name: %smile_attr_var(sashelp.class, name, varlen);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_attr_var(data, var, attrib);
+ %LOCAL dsid rc macro varnum;
+
+ %LET macro = &sysmacroname;
+
+ %* check: ATTRIB must contain valid options;
+ %IF %UPCASE(&attrib) NE VARTYPE AND
+ %UPCASE(&attrib) NE VARLEN AND
+ %UPCASE(&attrib) NE VARLABEL AND
+ %UPCASE(&attrib) NE VARFMT AND
+ %UPCASE(&attrib) NE VARINFMT
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib) - only the following are supported:;
+ %PUT ¯o - VARTYPE, VARLEN, VARLABEL, VARFMT and VARINFMT;
+ -1
+ %RETURN;
+ %END;
+
+ %* perform action and put value for processing;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
+ -1
+ %END;
+ %ELSE %DO;
+ %LET varnum = %SYSFUNC(VARNUM(&dsid,&var));
+ %IF &varnum LT 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Variable VAR (&var) does not exist in DATA (&data).;
+ -1
+ %RETURN;
+ %END;
+ %SYSFUNC(&attrib(&dsid,&varnum))
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %END;
+%MEND smile_attr_var;
diff --git a/macros/smile_attrc.sas b/macros/smile_attrc.sas
index 9cdcae2..4ec487d 100644
--- a/macros/smile_attrc.sas
+++ b/macros/smile_attrc.sas
@@ -1,59 +1,59 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_attrc
-%* Parameters : DATA - name of the SAS dataset
-%* ATTRIB - SAS ATTRC keyword (e.g. TYPE, LIB, LABEL, SORTEDBY, ...)
-%*
-%* Purpose : Function-style macro to return a character attribute of a dataset. The following attributes are available:
-%* CHARSET, COMPRESS, DATAREP, ENCODING, ENCRYPT, ENGINE, LABEL, LIB, MEM, MODE, MTYPE, SORTEDBY, SORTLVL,
-%* SORTSEQ, TYPE
-%*
-%* ExampleProg: ../programs/test_smile_attrc.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-02-19
-%* License : MIT
-%*
-%* Reference : Main programming parts are coming from attrc.sas macro from Roland Rashleigh-Berry who
-%* has published his code under the unlicence license in his utility package
-%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-%PUT library of dataset: %smile_attrc(sashelp.class, lib);
-PROC SORT DATA=sashelp.class OUT=class; BY sex name; RUN;
-%PUT class is sorted by: %smile_attrc(class, SORTEDBY);
-%PUT sashelp.class is sorted by: %smile_attrc(sashelp.class, SORTEDBY);
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_attrc(data, attrib) / MINOPERATOR MINDELIMITER=',';
- %LOCAL dsid rc macro;
-
- %LET macro = &sysmacroname;
-
- %* check: ATTRIB must contain valid options;
- %IF NOT (%UPCASE(&attrib) IN (CHARSET,COMPRESS,DATAREP,ENCODING,ENCRYPT,ENGINE,LABEL,LIB,MEM,MODE,MTYPE,
- SORTEDBY,SORTLVL,SORTSEQ,TYPE))
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib).;
- -1
- %RETURN;
- %END;
-
- %* perform action and put value for processing;
- %LET dsid=%SYSFUNC(OPEN(&data,is));
-
- %IF &dsid EQ 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
- -1
- %END;
- %ELSE %DO;
- %SYSFUNC(attrc(&dsid,&attrib))
- %LET rc=%SYSFUNC(CLOSE(&dsid));
- %END;
-%MEND smile_attrc;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_attrc
+%* Parameters : DATA - name of the SAS dataset
+%* ATTRIB - SAS ATTRC keyword (e.g. TYPE, LIB, LABEL, SORTEDBY, ...)
+%*
+%* Purpose : Function-style macro to return a character attribute of a dataset. The following attributes are available:
+%* CHARSET, COMPRESS, DATAREP, ENCODING, ENCRYPT, ENGINE, LABEL, LIB, MEM, MODE, MTYPE, SORTEDBY, SORTLVL,
+%* SORTSEQ, TYPE
+%*
+%* ExampleProg: ../programs/test_smile_attrc.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : Main programming parts are coming from attrc.sas macro from Roland Rashleigh-Berry who
+%* has published his code under the unlicence license in his utility package
+%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%PUT library of dataset: %smile_attrc(sashelp.class, lib);
+PROC SORT DATA=sashelp.class OUT=class; BY sex name; RUN;
+%PUT class is sorted by: %smile_attrc(class, SORTEDBY);
+%PUT sashelp.class is sorted by: %smile_attrc(sashelp.class, SORTEDBY);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_attrc(data, attrib) / MINOPERATOR MINDELIMITER=',';
+ %LOCAL dsid rc macro;
+
+ %LET macro = &sysmacroname;
+
+ %* check: ATTRIB must contain valid options;
+ %IF NOT (%UPCASE(&attrib) IN (CHARSET,COMPRESS,DATAREP,ENCODING,ENCRYPT,ENGINE,LABEL,LIB,MEM,MODE,MTYPE,
+ SORTEDBY,SORTLVL,SORTSEQ,TYPE))
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib).;
+ -1
+ %RETURN;
+ %END;
+
+ %* perform action and put value for processing;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
+ -1
+ %END;
+ %ELSE %DO;
+ %SYSFUNC(attrc(&dsid,&attrib))
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %END;
+%MEND smile_attrc;
diff --git a/macros/smile_attrn.sas b/macros/smile_attrn.sas
index bf9ffc7..138996c 100644
--- a/macros/smile_attrn.sas
+++ b/macros/smile_attrn.sas
@@ -1,59 +1,59 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_attrn
-%* Parameters : DATA - name of the SAS dataset
-%* ATTRIB - SAS ATTRN keyword (e.g. NOBS, CRDTE, ...)
-%*
-%* Purpose : Function-style macro to return a numeric attribute of a dataset. The following attributes are available:
-%* ALTERPW, ANOBS, ANY, ARAND, ARWU, AUDIT, AUDIT_DATA, AUDIT_BEFORE, AUDIT_ERROR, CRDTE, ICONST, INDEX,
-%* ISINDEX, ISSUBSET, LRECL, LRID, MAXGEN, MAXRC, MODTE, NDEL, NEXTGEN, NLOBS, NLOBSF, NOBS, NVARS, PW, RADIX,
-%* READPW, REUSE, TAPE, WHSTMT, WRITEPW
-%*
-%* ExampleProg: ../programs/test_smile_attrn.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-02-19
-%* License : MIT
-%*
-%* Reference : Main programming parts are coming from attrn.sas macro from Roland Rashleigh-Berry who
-%* has published his code under the unlicence license in his utility package
-%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-%PUT Number of observations: %smile_attrn(sashelp.class, nobs);
-%IF %smile_attrn(sashelp.class, nvars) > 0 %THEN %PUT Dataset has variables;
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_attrn(data, attrib) / MINOPERATOR MINDELIMITER=',';
- %LOCAL dsid rc macro;
-
- %LET macro = &sysmacroname;
-
- %* check: ATTRIB must contain valid options;
- %IF NOT (%UPCASE(&attrib) IN (ALTERPW,ANOBS,ANY,ARAND,ARWU,AUDIT,AUDIT_DATA,AUDIT_BEFORE,AUDIT_ERROR,CRDTE,ICONST,INDEX,
- ISINDEX,ISSUBSET,LRECL,LRID,MAXGEN,MAXRC,MODTE,NDEL,NEXTGEN,NLOBS,NLOBSF,NOBS,NVARS,PW,RADIX,
- READPW,REUSE,TAPE,WHSTMT,WRITEPW))
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib).;
- -1
- %RETURN;
- %END;
-
- %* perform action and put value for processing;
- %LET dsid=%SYSFUNC(OPEN(&data,is));
-
- %IF &dsid EQ 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
- -1
- %END;
- %ELSE %DO;
- %SYSFUNC(attrn(&dsid,&attrib))
- %LET rc=%SYSFUNC(CLOSE(&dsid));
- %END;
-%MEND smile_attrn;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_attrn
+%* Parameters : DATA - name of the SAS dataset
+%* ATTRIB - SAS ATTRN keyword (e.g. NOBS, CRDTE, ...)
+%*
+%* Purpose : Function-style macro to return a numeric attribute of a dataset. The following attributes are available:
+%* ALTERPW, ANOBS, ANY, ARAND, ARWU, AUDIT, AUDIT_DATA, AUDIT_BEFORE, AUDIT_ERROR, CRDTE, ICONST, INDEX,
+%* ISINDEX, ISSUBSET, LRECL, LRID, MAXGEN, MAXRC, MODTE, NDEL, NEXTGEN, NLOBS, NLOBSF, NOBS, NVARS, PW, RADIX,
+%* READPW, REUSE, TAPE, WHSTMT, WRITEPW
+%*
+%* ExampleProg: ../programs/test_smile_attrn.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : Main programming parts are coming from attrn.sas macro from Roland Rashleigh-Berry who
+%* has published his code under the unlicence license in his utility package
+%* (http://www.datasavantconsulting.com/roland/Spectre/download.html)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%PUT Number of observations: %smile_attrn(sashelp.class, nobs);
+%IF %smile_attrn(sashelp.class, nvars) > 0 %THEN %PUT Dataset has variables;
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_attrn(data, attrib) / MINOPERATOR MINDELIMITER=',';
+ %LOCAL dsid rc macro;
+
+ %LET macro = &sysmacroname;
+
+ %* check: ATTRIB must contain valid options;
+ %IF NOT (%UPCASE(&attrib) IN (ALTERPW,ANOBS,ANY,ARAND,ARWU,AUDIT,AUDIT_DATA,AUDIT_BEFORE,AUDIT_ERROR,CRDTE,ICONST,INDEX,
+ ISINDEX,ISSUBSET,LRECL,LRID,MAXGEN,MAXRC,MODTE,NDEL,NEXTGEN,NLOBS,NLOBSF,NOBS,NVARS,PW,RADIX,
+ READPW,REUSE,TAPE,WHSTMT,WRITEPW))
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - Invalid value for ATTRIB (&attrib).;
+ -1
+ %RETURN;
+ %END;
+
+ %* perform action and put value for processing;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist.;
+ -1
+ %END;
+ %ELSE %DO;
+ %SYSFUNC(attrn(&dsid,&attrib))
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %END;
+%MEND smile_attrn;
diff --git a/macros/smile_ods_document_flat_label.sas b/macros/smile_ods_document_flat_label.sas
index d19c2df..73c94f3 100644
--- a/macros/smile_ods_document_flat_label.sas
+++ b/macros/smile_ods_document_flat_label.sas
@@ -1,175 +1,175 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_ods_document_flat_label
-%* Parameters : DOCUMENT - ODS Document item store
-%* LABEL - One label to apply on first element, all other labels are removed (optional),
-%* if not provided, labels are just rearranged and additional BY-labels removed
-%* BOOKMARKLABEL - Indicator whether to use Bookmark Labels if none is specified (YES Default),
-%* if LABEL is missing and BOOKMARKLABEL = NO, all labels are removed
-%*
-%* Purpose : Flat navigation and optionally re-label navigation for ODS DOCUMENT. The navigation bookmark level is
-%* reduced to one level only. Optionally a label can be applied to all content items or the navigation label
-%* can be removed completely.
-%* Comment : The navigation in PDF documents can be one level only with this macro. CONTENTS="" must be applied to
-%* the PROC REPORT as option and additionally for a BREAK BEFORE PAGE option.
-%* Issues : The table of contents created per default by SAS (ODS PDF option TOC) is not linking the pages correctly when
-%* using BY groups and having one ODS DOCUMENT with multiple outputs, using single ODS DOCUMENTS (one per each output)
-%* then this is working correctly. In such a case, do use not a TOC or create an own TOC, e.g. like described here:
-%* https://www.mwsug.org/proceedings/2012/S1/MWSUG-2012-S125.pdf
-%*
-%* ExampleProg: ../programs/test_smile_ods_document_flat_label.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-02-15
-%* License : MIT
-%*
-%* Reference : A nice overview of ODS DOCUMENT can be found here: https://support.sas.com/resources/papers/proceedings12/273-2012.pdf
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-%*This will flatten the navigation and use the labels originally set with ODS PROCLABEL;
-%smile_ods_document_flat_label(document=doc_reports);
-
-%*This will flatten the navigation and use the label "Table 1.1.1" applied to all items of this store;
-%smile_ods_document_flat_label(document=doc_report1, label=Table 1.1.1);
-
-%*This will flatten the navigation and use no navigation label at all (no navigation link at all for these items);
-%smile_ods_document_flat_label(document=doc_report1, label=, bookmarklabel = NO);
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_ods_document_flat_label(document=, label=, bookmarkLabel = yes);
-
- %LOCAL macro _temp;
- %LET macro = &sysmacroname;
- %LET _temp = -1;
-
-%*;
-%* Error handling I;
-%*;
-
- %* check: DOCUMENT must be specified;
- %IF %LENGTH(&document) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DOCUMENT parameter is required. Macro will abort;
- %RETURN;
- %END;
-
- %* check: BOOKMARKLABEL must be YES or NO;
- %IF %UPCASE(&bookmarkLabel) NE YES AND %UPCASE(&bookmarkLabel) NE NO
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - BOOKMARKLABEL parameter must either be NO or YES. Macro will abort;
- %RETURN;
- %END;
-
- %* check - DOCUMENT must be an existing item store in WORK;
- PROC SQL NOPRINT;
- SELECT 1 INTO :_temp FROM SASHELP.VMEMBER
- WHERE libname="WORK" AND memname="%UPCASE(&document)" AND memtype = "ITEMSTOR";
- RUN;QUIT;
- %IF &_temp NE 1
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DOCUMENT (&document) is no existing ODS DOCUMENT. Macro will abort;
- %RETURN;
- %END;
-
-%*;
-%* Read information;
-%*;
-
- ODS SELECT NONE;
- PROC DOCUMENT NAME = &document;
- LIST / DETAILS LEVELS=all;
- ODS OUTPUT PROPERTIES = _props;
- RUN;QUIT;
- ODS SELECT ALL;
-
-%*;
-%* Error handling II;
-%*;
-
- %* check: DOCUMENT must contain content;
- %LET _temp = -1;
- PROC SQL NOPRINT;
- SELECT nobs INTO :_temp FROM SASHELP.VTABLE WHERE libname="WORK" AND memname="_PROPS";
- RUN;QUIT;
- %IF &_temp = 0
- %THEN %DO;
- %PUT %STR(WAR)NING: ¯o - DOCUMENT (&document) does not contain any observations - no action done;
- %RETURN;
- %END;
-
-%*;
-%* Processing;
-%*;
-
- %* create a generic processing for PROC DOCUMENT;
- %* Step 1: move all reports to /all and apply label;
- DATA _NULL_;
- SET _props END=_eof;
- ATTRIB coreLabel FORMAT=$200.;
- RETAIN coreLabel;
- RETAIN _count 1 _first 0 _core 0;
-
- IF _N_ = 1
- THEN DO;
- CALL EXECUTE("PROC DOCUMENT NAME=&document;");
- END;
-
- IF COUNT(path,"\") = 1 AND type = "Dir"
- THEN DO;
- _core = 1;
- %IF %UPCASE(&bookmarkLabel) NE YES
- %THEN %DO;
- CALL MISSING(coreLabel);
- PUT "updateOdsDocument - No label is used";
- %END;
- %ELSE %IF %LENGTH("&label") > 2
- %THEN %DO;
- coreLabel = "&label";
- %END;
- %ELSE %DO;
- coreLabel = label;
- _first = 0;
-
- %END;
- END;
-
- IF type NE "Dir" AND _core
- THEN DO;
- CALL EXECUTE('MOVE ' || STRIP(path) || ' to \all;');
- IF _first = 0
- THEN CALL EXECUTE('SETLABEL \all#' || STRIP(PUT(_count,BEST.)) || " '" || STRIP(coreLabel) || "';");
- _first = 1;
- _count = _count + 1;
- END;
-
- IF _eof
- THEN DO;
- CALL EXECUTE('RUN;QUIT;');
- END;
- RUN;
-
- %* Step 2: remove all old hierarchies;
- DATA _NULL_;
- SET _props END=_eof;
- IF _N_ = 1
- THEN CALL EXECUTE("PROC DOCUMENT NAME=&document;");
- IF COUNT(path,"\") = 1 AND type = "Dir"
- THEN CALL EXECUTE('DELETE ' || STRIP(path) || ";");
- IF _eof
- THEN CALL EXECUTE('RUN;QUIT;');
- RUN;
-
-%*;
-%* Cleanup;
-%*;
-
- PROC DATASETS LIB=WORK;
- DELETE _props;
- RUN;
-
-%MEND smile_ods_document_flat_label;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_ods_document_flat_label
+%* Parameters : DOCUMENT - ODS Document item store
+%* LABEL - One label to apply on first element, all other labels are removed (optional),
+%* if not provided, labels are just rearranged and additional BY-labels removed
+%* BOOKMARKLABEL - Indicator whether to use Bookmark Labels if none is specified (YES Default),
+%* if LABEL is missing and BOOKMARKLABEL = NO, all labels are removed
+%*
+%* Purpose : Flat navigation and optionally re-label navigation for ODS DOCUMENT. The navigation bookmark level is
+%* reduced to one level only. Optionally a label can be applied to all content items or the navigation label
+%* can be removed completely.
+%* Comment : The navigation in PDF documents can be one level only with this macro. CONTENTS="" must be applied to
+%* the PROC REPORT as option and additionally for a BREAK BEFORE PAGE option.
+%* Issues : The table of contents created per default by SAS (ODS PDF option TOC) is not linking the pages correctly when
+%* using BY groups and having one ODS DOCUMENT with multiple outputs, using single ODS DOCUMENTS (one per each output)
+%* then this is working correctly. In such a case, do use not a TOC or create an own TOC, e.g. like described here:
+%* https://www.mwsug.org/proceedings/2012/S1/MWSUG-2012-S125.pdf
+%*
+%* ExampleProg: ../programs/test_smile_ods_document_flat_label.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-15
+%* License : MIT
+%*
+%* Reference : A nice overview of ODS DOCUMENT can be found here: https://support.sas.com/resources/papers/proceedings12/273-2012.pdf
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%*This will flatten the navigation and use the labels originally set with ODS PROCLABEL;
+%smile_ods_document_flat_label(document=doc_reports);
+
+%*This will flatten the navigation and use the label "Table 1.1.1" applied to all items of this store;
+%smile_ods_document_flat_label(document=doc_report1, label=Table 1.1.1);
+
+%*This will flatten the navigation and use no navigation label at all (no navigation link at all for these items);
+%smile_ods_document_flat_label(document=doc_report1, label=, bookmarklabel = NO);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_ods_document_flat_label(document=, label=, bookmarkLabel = yes);
+
+ %LOCAL macro _temp;
+ %LET macro = &sysmacroname;
+ %LET _temp = -1;
+
+%*;
+%* Error handling I;
+%*;
+
+ %* check: DOCUMENT must be specified;
+ %IF %LENGTH(&document) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DOCUMENT parameter is required. Macro will abort;
+ %RETURN;
+ %END;
+
+ %* check: BOOKMARKLABEL must be YES or NO;
+ %IF %UPCASE(&bookmarkLabel) NE YES AND %UPCASE(&bookmarkLabel) NE NO
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - BOOKMARKLABEL parameter must either be NO or YES. Macro will abort;
+ %RETURN;
+ %END;
+
+ %* check - DOCUMENT must be an existing item store in WORK;
+ PROC SQL NOPRINT;
+ SELECT 1 INTO :_temp FROM SASHELP.VMEMBER
+ WHERE libname="WORK" AND memname="%UPCASE(&document)" AND memtype = "ITEMSTOR";
+ RUN;QUIT;
+ %IF &_temp NE 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DOCUMENT (&document) is no existing ODS DOCUMENT. Macro will abort;
+ %RETURN;
+ %END;
+
+%*;
+%* Read information;
+%*;
+
+ ODS SELECT NONE;
+ PROC DOCUMENT NAME = &document;
+ LIST / DETAILS LEVELS=all;
+ ODS OUTPUT PROPERTIES = _props;
+ RUN;QUIT;
+ ODS SELECT ALL;
+
+%*;
+%* Error handling II;
+%*;
+
+ %* check: DOCUMENT must contain content;
+ %LET _temp = -1;
+ PROC SQL NOPRINT;
+ SELECT nobs INTO :_temp FROM SASHELP.VTABLE WHERE libname="WORK" AND memname="_PROPS";
+ RUN;QUIT;
+ %IF &_temp = 0
+ %THEN %DO;
+ %PUT %STR(WAR)NING: ¯o - DOCUMENT (&document) does not contain any observations - no action done;
+ %RETURN;
+ %END;
+
+%*;
+%* Processing;
+%*;
+
+ %* create a generic processing for PROC DOCUMENT;
+ %* Step 1: move all reports to /all and apply label;
+ DATA _NULL_;
+ SET _props END=_eof;
+ ATTRIB coreLabel FORMAT=$200.;
+ RETAIN coreLabel;
+ RETAIN _count 1 _first 0 _core 0;
+
+ IF _N_ = 1
+ THEN DO;
+ CALL EXECUTE("PROC DOCUMENT NAME=&document;");
+ END;
+
+ IF COUNT(path,"\") = 1 AND type = "Dir"
+ THEN DO;
+ _core = 1;
+ %IF %UPCASE(&bookmarkLabel) NE YES
+ %THEN %DO;
+ CALL MISSING(coreLabel);
+ PUT "updateOdsDocument - No label is used";
+ %END;
+ %ELSE %IF %LENGTH("&label") > 2
+ %THEN %DO;
+ coreLabel = "&label";
+ %END;
+ %ELSE %DO;
+ coreLabel = label;
+ _first = 0;
+
+ %END;
+ END;
+
+ IF type NE "Dir" AND _core
+ THEN DO;
+ CALL EXECUTE('MOVE ' || STRIP(path) || ' to \all;');
+ IF _first = 0
+ THEN CALL EXECUTE('SETLABEL \all#' || STRIP(PUT(_count,BEST.)) || " '" || STRIP(coreLabel) || "';");
+ _first = 1;
+ _count = _count + 1;
+ END;
+
+ IF _eof
+ THEN DO;
+ CALL EXECUTE('RUN;QUIT;');
+ END;
+ RUN;
+
+ %* Step 2: remove all old hierarchies;
+ DATA _NULL_;
+ SET _props END=_eof;
+ IF _N_ = 1
+ THEN CALL EXECUTE("PROC DOCUMENT NAME=&document;");
+ IF COUNT(path,"\") = 1 AND type = "Dir"
+ THEN CALL EXECUTE('DELETE ' || STRIP(path) || ";");
+ IF _eof
+ THEN CALL EXECUTE('RUN;QUIT;');
+ RUN;
+
+%*;
+%* Cleanup;
+%*;
+
+ PROC DATASETS LIB=WORK;
+ DELETE _props;
+ RUN;
+
+%MEND smile_ods_document_flat_label;
diff --git a/macros/smile_pdf_merge.sas b/macros/smile_pdf_merge.sas
index 810d403..47695f1 100644
--- a/macros/smile_pdf_merge.sas
+++ b/macros/smile_pdf_merge.sas
@@ -1,280 +1,280 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_pdf_merge
-%* Parameters : DATA - Input dataset containing INFILE and BOOKMARK variable,
-%* INFILE containing single pdf files (one file per observation),
-%* BOOKMARK containing the corresponding bookmark label for this file
-%* OUTFILE - Output PDF file (not in quotes)
-%* PDFBOX_JAR_PATH - Path and jar file name for PDFBOX open source tool, e.g. &path/pdfbox-app-2.0.22.jar
-%* SOURCEFILE - Optional SAS program file where PROC GROOVY code is stored, default is TEMP (only temporary)
-%* RUN_GROOVY - NO/YES indicator whether to run the final GROOVY code (default YES)
-%*
-%* Purpose : Merge multiple PDF files and create one bookmark entry per PDF file with PROC GROOVY and open-source Tool PDFBox
-%* Comment : Make sure to download PDFBOX, e.g. from here https://pdfbox.apache.org/download.html - the full "app" version
-%* Issues : "unable to resolve class" messages mean the PDFBOX is not provided correctly.
-%* "ERROR: PROCEDURE GROOVY cannot be used when SAS is in the lock down state." means that your SAS environment
-%* does not support PROC GROOVY, for this the macro cannot run the groovy code.
-%* "WARNUNG: Removed /IDTree from /Names dictionary, doesn't belong there" - this message is coming from PDFBox.
-%*
-%* ExampleProg: ../programs/test_smile_pdf_merge.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-01-29
-%* License : MIT
-%*
-%* Reference : A paper explaining how to use PDFBOX with PROC GROOVY also for TOC is available in the following paper
-%* (https://www.lexjansen.com/phuse/2019/ct/CT05.pdf)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-DATA content;
- ATTRIB inFile FORMAT=$255.;
- ATTRIB bookmark FORMAT=$255.;
- inFile = "&inPath/output_1.pdf"; bookmark = "Table 1"; OUTPUT;
- inFile = "&inPath/output_2.pdf"; bookmark = "Table 2"; OUTPUT;
- inFile = "&inPath/output_3.pdf"; bookmark = "Table 3"; OUTPUT;
-RUN;
-%smile_pdf_merge(
- data = content
- , outfile = &outPath/merged_output.pdf
- , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
- , sourcefile = &progPath/groovy_call.sas
- , run_groovy = YES
-);
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_pdf_merge(data = , outfile = , pdfbox_jar_path = , sourcefile = TEMP, run_groovy = YES);
-
- %LOCAL macro;
- %LET macro = &sysmacroname;
-
-%*;
-%* Error handling I - parameter checks;
-%*;
-
- %* check: existence of required parameters (DATA, OUTFILE, PDFBOX_JAR_PATH), abort;
- %* check: existence of parameter SOURCEFILE, if not use TEMP;
- %* check: RUN_GROOVY must be NO or YES, abort;
-
- %IF %LENGTH(&data) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA parameter is requried. Macro will abort.;
- %RETURN;
- %END;
-
- %IF %LENGTH(&outfile) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - OUTFILE parameter is requried. Macro will abort.;
- %RETURN;
- %END;
-
- %IF %LENGTH(&pdfbox_jar_path) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH parameter is requried. Macro will abort.;
- %RETURN;
- %END;
-
- %IF %LENGTH(&sourcefile) = 0
- %THEN %DO;
- %PUT %STR(WAR)NING: ¯o - SOURCEFILE parameter is needed - TEMP will be used.;
- %LET sourcefile = TEMP;
- %END;
-
- %IF %UPCASE(&run_groovy) NE YES AND %UPCASE(&run_groovy) NE NO
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - RUN_GROOVY parameter must be NO or YES. Macro will abort.;
- %RETURN;
- %END;
-
- %* check: PDFBOX_JAR_PATH must exist and must be a ".jar" file;
- %IF %SYSFUNC(FILEEXIST(&pdfbox_jar_path)) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH file does not exist. Macro will abort.;
- %RETURN;
- %END;
- %IF %UPCASE(%SCAN(&pdfbox_jar_path,-1,.)) NE JAR
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH must be a ".jar" file. Macro will abort.;
- %RETURN;
- %END;
-
-%*;
-%* Preparations;
-%*;
-
- %* include quotes around sourcefile if not available;
- DATA _NULL_;
- ATTRIB path FORMAT=$500.;
- path = SYMGET('sourcefile');
- IF UPCASE(STRIP(path)) NE "TEMP"
- THEN DO;
- IF SUBSTR(sourcefile,1,1) NE '"' AND SUBSTR(sourcefile,1,1) NE "'"
- THEN DO;
- CALL SYMPUT('sourcefile','"' || STRIP(path) || '"');
- END;
- END;
- RUN;
-
-%*;
-%* Error handling II - data checks;
-%*;
-
- %LOCAL dsid rc error;
- %LET error = 0;
-
- %* check: existence of data, contains observations, contains variables infile and bookmark;
- %LET dsid=%SYSFUNC(OPEN(&data,is));
- %IF &dsid EQ 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist. Macro will abort.;
- %RETURN;
- %END;
- %ELSE %IF %SYSFUNC(ATTRN(&dsid,NLOBS)) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA (&data) does not contain any observations. Macro will abort.;
- %LET rc=%SYSFUNC(CLOSE(&dsid));
- %RETURN;
- %END;
- %ELSE %IF %SYSFUNC(VARNUM(&dsid,infile)) = 0 OR %SYSFUNC(VARNUM(&dsid,bookmark)) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - DATA (&data) does not contain required variables (infile and bookmark). Macro will abort.;
- %LET rc=%SYSFUNC(CLOSE(&dsid));
- %RETURN;
- %END;
- %LET rc=%SYSFUNC(CLOSE(&dsid));
-
- %* check: files in variable "infile" must exist;
- %* update BOOKMARK labels, replace double quotes;
- DATA _smile_indat;
- SET &data;
- RETAIN _smile_msg 0;
- IF FILEEXIST(infile) = 0
- THEN DO;
- PUT "%STR(ERR)OR: INFILE does not exist: " infile " - Macro will abort.";
- CALL SYMPUT('error','1');
- END;
- IF INDEX(bookmark,'"') > 0 AND _smile_msg = 0
- THEN DO;
- PUT "%STR(WAR)NING: Double quotes are not supported for BOOKMARK texts and are removed.";
- _smile_msg = 1;
- END;
- bookmark = TRANWRD(bookmark,'"','');
- RUN;
-
- %IF &error NE 0
- %THEN %DO;
- %GOTO end_macro;
- %END;
-
-%*;
-%* Create PROC GROOVY program file;
-%*;
-
- FILENAME cmd &sourcefile;
-
- DATA _NULL_;
- FILE cmd LRECL=5000;
- SET _smile_indat END=_eof;
- IF _N_ = 1
- THEN DO;
- PUT "PROC GROOVY;";
- PUT " ADD CLASSPATH = ""&pdfbox_jar_path"";";
- PUT " SUBMIT;";
- PUT ;
- PUT "import org.apache.pdfbox.multipdf.PDFMergerUtility;";
- PUT "import org.apache.pdfbox.pdmodel.PDDocument;";
- PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;";
- PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination;";
- PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;";
- PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;";
- PUT "import java.io.File;";
- PUT ;
- PUT "public class PDFMerge2 {";
- PUT " public static void main(String[] args) {";
- PUT;
- PUT @8 "//Instantiating PDFMergerUtility class";
- PUT @8 "PDFMergerUtility PDFmerger = new PDFMergerUtility();";
- PUT ;
- PUT @8 "//Setting the destination file";
- PUT @8 "PDFmerger.setDestinationFileName(""&outfile"");";
- PUT ;
- PUT @8 "//adding the source files";
- END;
- PUT @8 "PDFmerger.addSource(new File(""" inFile +(-1) """));";
- IF _eof
- THEN DO;
- PUT @8 "PDFmerger.mergeDocuments(null);";
- END;
- RUN;
-
- DATA _NULL_;
- FILE cmd LRECL=5000 MOD;
- ATTRIB _temp FORMAT=$200.;
- SET _smile_indat END=_eof;
- IF _N_ = 1
- THEN DO;
- PUT @8 "//Open created document";
- PUT @8 "PDDocument document;";
- PUT @8 "PDPageDestination pageDestination;";
- PUT @8 "PDOutlineItem bookmark;";
- PUT @8 "document = PDDocument.load(new File(""&outfile""));";
- PUT ;
- PUT @8 "//Create a bookmark outline";
- PUT @8 "PDDocumentOutline documentOutline = new PDDocumentOutline();";
- PUT @8 "document.getDocumentCatalog().setDocumentOutline(documentOutline);";
- PUT @8 ;
- PUT @8 "int currentPage = 0;";
- END;
-
- _temp = SCAN(inFile,-1,"/\");
- PUT @8 "//Include file " _temp;
- PUT @8 "pageDestination = new PDPageFitWidthDestination();";
- PUT @8 "pageDestination.setPage(document.getPage(currentPage));";
- PUT @8 "bookmark = new PDOutlineItem();";
- PUT @8 "bookmark.setDestination(pageDestination);";
- PUT @8 "bookmark.setTitle(""" bookmark +(-1) """);";
- PUT @8 "documentOutline.addLast(bookmark);";
- PUT ;
- PUT @8 "//Change currentPage number";
- PUT @8 "currentPage += PDDocument.load(new File(""" inFile +(-1) """)).getNumberOfPages();";
- PUT ;
- IF _eof
- THEN DO;
- PUT @8 "//save document";
- PUT @8 "document.save(""&outfile"");";
- PUT ;
- PUT "}}";
- PUT "endsubmit;";
- PUT "quit;";
- END;
- RUN;
-
-%*;
-%* Optionally execute PROC GROOVY code;
-%*;
-
- %IF %UPCASE(&run_groovy) = YES
- %THEN %DO;
- %PUT ¯o: Run Groovy Program;
- %PUT ¯o: The following warning might come from PDFBox: %STR(WAR)NING: Removed /IDTree from /Names dictionary ...;
- %INCLUDE cmd;
- %END;
-
-%end_macro:
-
-%*;
-%* cleanup;
-%*;
-
- FILENAME cmd;
-
- PROC DATASETS LIB=WORK NOWARN NOLIST;
- DELETE _smile_indat;
- RUN;
-
-
-%MEND;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_pdf_merge
+%* Parameters : DATA - Input dataset containing INFILE and BOOKMARK variable,
+%* INFILE containing single pdf files (one file per observation),
+%* BOOKMARK containing the corresponding bookmark label for this file
+%* OUTFILE - Output PDF file (not in quotes)
+%* PDFBOX_JAR_PATH - Path and jar file name for PDFBOX open source tool, e.g. &path/pdfbox-app-2.0.22.jar
+%* SOURCEFILE - Optional SAS program file where PROC GROOVY code is stored, default is TEMP (only temporary)
+%* RUN_GROOVY - NO/YES indicator whether to run the final GROOVY code (default YES)
+%*
+%* Purpose : Merge multiple PDF files and create one bookmark entry per PDF file with PROC GROOVY and open-source Tool PDFBox
+%* Comment : Make sure to download PDFBOX, e.g. from here https://pdfbox.apache.org/download.html - the full "app" version
+%* Issues : "unable to resolve class" messages mean the PDFBOX is not provided correctly.
+%* "ERROR: PROCEDURE GROOVY cannot be used when SAS is in the lock down state." means that your SAS environment
+%* does not support PROC GROOVY, for this the macro cannot run the groovy code.
+%* "WARNUNG: Removed /IDTree from /Names dictionary, doesn't belong there" - this message is coming from PDFBox.
+%*
+%* ExampleProg: ../programs/test_smile_pdf_merge.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-01-29
+%* License : MIT
+%*
+%* Reference : A paper explaining how to use PDFBOX with PROC GROOVY also for TOC is available in the following paper
+%* (https://www.lexjansen.com/phuse/2019/ct/CT05.pdf)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+DATA content;
+ ATTRIB inFile FORMAT=$255.;
+ ATTRIB bookmark FORMAT=$255.;
+ inFile = "&inPath/output_1.pdf"; bookmark = "Table 1"; OUTPUT;
+ inFile = "&inPath/output_2.pdf"; bookmark = "Table 2"; OUTPUT;
+ inFile = "&inPath/output_3.pdf"; bookmark = "Table 3"; OUTPUT;
+RUN;
+%smile_pdf_merge(
+ data = content
+ , outfile = &outPath/merged_output.pdf
+ , pdfbox_jar_path = &libPath/pdfbox-app-2.0.22.jar
+ , sourcefile = &progPath/groovy_call.sas
+ , run_groovy = YES
+);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_pdf_merge(data = , outfile = , pdfbox_jar_path = , sourcefile = TEMP, run_groovy = YES);
+
+ %LOCAL macro;
+ %LET macro = &sysmacroname;
+
+%*;
+%* Error handling I - parameter checks;
+%*;
+
+ %* check: existence of required parameters (DATA, OUTFILE, PDFBOX_JAR_PATH), abort;
+ %* check: existence of parameter SOURCEFILE, if not use TEMP;
+ %* check: RUN_GROOVY must be NO or YES, abort;
+
+ %IF %LENGTH(&data) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA parameter is requried. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&outfile) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - OUTFILE parameter is requried. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&pdfbox_jar_path) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH parameter is requried. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&sourcefile) = 0
+ %THEN %DO;
+ %PUT %STR(WAR)NING: ¯o - SOURCEFILE parameter is needed - TEMP will be used.;
+ %LET sourcefile = TEMP;
+ %END;
+
+ %IF %UPCASE(&run_groovy) NE YES AND %UPCASE(&run_groovy) NE NO
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - RUN_GROOVY parameter must be NO or YES. Macro will abort.;
+ %RETURN;
+ %END;
+
+ %* check: PDFBOX_JAR_PATH must exist and must be a ".jar" file;
+ %IF %SYSFUNC(FILEEXIST(&pdfbox_jar_path)) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH file does not exist. Macro will abort.;
+ %RETURN;
+ %END;
+ %IF %UPCASE(%SCAN(&pdfbox_jar_path,-1,.)) NE JAR
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - PDFBOX_JAR_PATH must be a ".jar" file. Macro will abort.;
+ %RETURN;
+ %END;
+
+%*;
+%* Preparations;
+%*;
+
+ %* include quotes around sourcefile if not available;
+ DATA _NULL_;
+ ATTRIB path FORMAT=$500.;
+ path = SYMGET('sourcefile');
+ IF UPCASE(STRIP(path)) NE "TEMP"
+ THEN DO;
+ IF SUBSTR(sourcefile,1,1) NE '"' AND SUBSTR(sourcefile,1,1) NE "'"
+ THEN DO;
+ CALL SYMPUT('sourcefile','"' || STRIP(path) || '"');
+ END;
+ END;
+ RUN;
+
+%*;
+%* Error handling II - data checks;
+%*;
+
+ %LOCAL dsid rc error;
+ %LET error = 0;
+
+ %* check: existence of data, contains observations, contains variables infile and bookmark;
+ %LET dsid=%SYSFUNC(OPEN(&data,is));
+ %IF &dsid EQ 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not exist. Macro will abort.;
+ %RETURN;
+ %END;
+ %ELSE %IF %SYSFUNC(ATTRN(&dsid,NLOBS)) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not contain any observations. Macro will abort.;
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %RETURN;
+ %END;
+ %ELSE %IF %SYSFUNC(VARNUM(&dsid,infile)) = 0 OR %SYSFUNC(VARNUM(&dsid,bookmark)) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - DATA (&data) does not contain required variables (infile and bookmark). Macro will abort.;
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+ %RETURN;
+ %END;
+ %LET rc=%SYSFUNC(CLOSE(&dsid));
+
+ %* check: files in variable "infile" must exist;
+ %* update BOOKMARK labels, replace double quotes;
+ DATA _smile_indat;
+ SET &data;
+ RETAIN _smile_msg 0;
+ IF FILEEXIST(infile) = 0
+ THEN DO;
+ PUT "%STR(ERR)OR: INFILE does not exist: " infile " - Macro will abort.";
+ CALL SYMPUT('error','1');
+ END;
+ IF INDEX(bookmark,'"') > 0 AND _smile_msg = 0
+ THEN DO;
+ PUT "%STR(WAR)NING: Double quotes are not supported for BOOKMARK texts and are removed.";
+ _smile_msg = 1;
+ END;
+ bookmark = TRANWRD(bookmark,'"','');
+ RUN;
+
+ %IF &error NE 0
+ %THEN %DO;
+ %GOTO end_macro;
+ %END;
+
+%*;
+%* Create PROC GROOVY program file;
+%*;
+
+ FILENAME cmd &sourcefile;
+
+ DATA _NULL_;
+ FILE cmd LRECL=5000;
+ SET _smile_indat END=_eof;
+ IF _N_ = 1
+ THEN DO;
+ PUT "PROC GROOVY;";
+ PUT " ADD CLASSPATH = ""&pdfbox_jar_path"";";
+ PUT " SUBMIT;";
+ PUT ;
+ PUT "import org.apache.pdfbox.multipdf.PDFMergerUtility;";
+ PUT "import org.apache.pdfbox.pdmodel.PDDocument;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageFitWidthDestination;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;";
+ PUT "import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;";
+ PUT "import java.io.File;";
+ PUT ;
+ PUT "public class PDFMerge2 {";
+ PUT " public static void main(String[] args) {";
+ PUT;
+ PUT @8 "//Instantiating PDFMergerUtility class";
+ PUT @8 "PDFMergerUtility PDFmerger = new PDFMergerUtility();";
+ PUT ;
+ PUT @8 "//Setting the destination file";
+ PUT @8 "PDFmerger.setDestinationFileName(""&outfile"");";
+ PUT ;
+ PUT @8 "//adding the source files";
+ END;
+ PUT @8 "PDFmerger.addSource(new File(""" inFile +(-1) """));";
+ IF _eof
+ THEN DO;
+ PUT @8 "PDFmerger.mergeDocuments(null);";
+ END;
+ RUN;
+
+ DATA _NULL_;
+ FILE cmd LRECL=5000 MOD;
+ ATTRIB _temp FORMAT=$200.;
+ SET _smile_indat END=_eof;
+ IF _N_ = 1
+ THEN DO;
+ PUT @8 "//Open created document";
+ PUT @8 "PDDocument document;";
+ PUT @8 "PDPageDestination pageDestination;";
+ PUT @8 "PDOutlineItem bookmark;";
+ PUT @8 "document = PDDocument.load(new File(""&outfile""));";
+ PUT ;
+ PUT @8 "//Create a bookmark outline";
+ PUT @8 "PDDocumentOutline documentOutline = new PDDocumentOutline();";
+ PUT @8 "document.getDocumentCatalog().setDocumentOutline(documentOutline);";
+ PUT @8 ;
+ PUT @8 "int currentPage = 0;";
+ END;
+
+ _temp = SCAN(inFile,-1,"/\");
+ PUT @8 "//Include file " _temp;
+ PUT @8 "pageDestination = new PDPageFitWidthDestination();";
+ PUT @8 "pageDestination.setPage(document.getPage(currentPage));";
+ PUT @8 "bookmark = new PDOutlineItem();";
+ PUT @8 "bookmark.setDestination(pageDestination);";
+ PUT @8 "bookmark.setTitle(""" bookmark +(-1) """);";
+ PUT @8 "documentOutline.addLast(bookmark);";
+ PUT ;
+ PUT @8 "//Change currentPage number";
+ PUT @8 "currentPage += PDDocument.load(new File(""" inFile +(-1) """)).getNumberOfPages();";
+ PUT ;
+ IF _eof
+ THEN DO;
+ PUT @8 "//save document";
+ PUT @8 "document.save(""&outfile"");";
+ PUT ;
+ PUT "}}";
+ PUT "endsubmit;";
+ PUT "quit;";
+ END;
+ RUN;
+
+%*;
+%* Optionally execute PROC GROOVY code;
+%*;
+
+ %IF %UPCASE(&run_groovy) = YES
+ %THEN %DO;
+ %PUT ¯o: Run Groovy Program;
+ %PUT ¯o: The following warning might come from PDFBox: %STR(WAR)NING: Removed /IDTree from /Names dictionary ...;
+ %INCLUDE cmd;
+ %END;
+
+%end_macro:
+
+%*;
+%* cleanup;
+%*;
+
+ FILENAME cmd;
+
+ PROC DATASETS LIB=WORK NOWARN NOLIST;
+ DELETE _smile_indat;
+ RUN;
+
+
+%MEND;
diff --git a/macros/smile_pdf_read_bookmarks.sas b/macros/smile_pdf_read_bookmarks.sas
index 71f3b83..fe0d159 100644
--- a/macros/smile_pdf_read_bookmarks.sas
+++ b/macros/smile_pdf_read_bookmarks.sas
@@ -1,108 +1,108 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_pdf_read_bookmarks
-%* Parameters : PDFFILE - name of PDF file with bookmarks
-%* OUTDAT - output dataset
-%* PDFBOX_JAR - path and jar file name for PDFBOX open source tool, e.g. &path/pdfbox-app-2.0.22.jar
-%*
-%* Purpose : Read PDF Bookmarks into a SAS dataset with the variables level, title and page
-%* Comment : Make sure to download PDFBOX, e.g. from here https://pdfbox.apache.org/download.html - the full "app" version
-%* Issues : "unable to resolve class" messages mean the PDFBOX is not provided correctly.
-%* "ERROR: PROCEDURE GROOVY cannot be used when SAS is in the lock down state." means that your SAS environment
-%* does not support PROC GROOVY, for this the macro cannot run the groovy code.
-%*
-%* ExampleProg: ../programs/test_smile_pdf_read_bookmarks.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-02-13
-%* License : MIT
-%*
-%* Reference : PDFBox contains a lot of useful functionalities (https://pdfbox.apache.org)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-%smile_pdf_read_bookmarks(pdfFile = /ods_document_flat1.pdf,
- outdat = book_flat1,
- pdfbox_jar_path = /pdfbox-app-2.0.22.jar)
-
-%smile_pdf_read_bookmarks(pdfFile = /ods_document_noflat1.pdf,
- outdat = book_noflat1,
- pdfbox_jar_path = /pdfbox-app-2.0.22.jar)
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_pdf_read_bookmarks(pdfFile = , outdat = , pdfbox_jar_path = );
-
- %LOCAL jsonFile;
-
- FILENAME jsonFile TEMP;
- %LET jsonFile = %SYSFUNC(PATHNAME(jsonFile));
-
- FILENAME _rdbkpd TEMP;
- DATA _NULL_;
- FILE _rdbkpd LRECL=5000;
-
- PUT 'PROC GROOVY;';
- PUT ' ADD CLASSPATH = "' "&pdfbox_jar_path" '";';
- PUT ' SUBMIT;';
- PUT ;
- PUT ' import java.io.File;';
- PUT ' import java.io.FileWriter;';
- PUT ' import java.io.IOException;';
- PUT ' import java.io.PrintWriter;';
- PUT ' import java.util.ArrayList;';
- PUT ;
- PUT ' import org.apache.pdfbox.pdmodel.PDDocument;';
- PUT ' import org.apache.pdfbox.pdmodel.PDPage;';
- PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;';
- PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;';
- PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode;';
- PUT ;
- PUT ' public class PDFReadBookmarks {';
- PUT ;
- PUT ' public static void main(String[] args) throws IOException {';
- PUT ' ArrayList aBookmarks = new ArrayList();';
- PUT ;
- PUT ' // Read the PDF document and investigate bookmarks into a list (JSON formatted)';
- PUT ' PDDocument document = PDDocument.load(new File("' "&pdffile" '"));';
- PUT ' PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();';
- PUT ' addBookmark(aBookmarks, document, outline, 1);';
- PUT ' document.close();';
- PUT ;
- PUT ' // Print bookmark information into a file';
- PUT ' FileWriter fileWriter = new FileWriter("' "&jsonFile" '");';
- PUT ' PrintWriter printWriter = new PrintWriter(fileWriter);';
- PUT ' printWriter.print(aBookmarks);';
- PUT ' printWriter.close();';
- PUT ' }';
- PUT ;
- PUT ' static public void addBookmark(ArrayList bookmarks, PDDocument document, PDOutlineNode bookmark, int level) throws IOException';
- PUT ' {';
- PUT ' PDOutlineItem current = bookmark.getFirstChild();';
- PUT ' while (current != null)';
- PUT ' {';
- PUT ' PDPage currentPage = current.findDestinationPage(document);';
- PUT ' Integer pageNumber = document.getDocumentCatalog().getPages().indexOf(currentPage) + 1;';
- PUT ' String text = "\n{\"level\":" + level + ", \"title\":\"" + current.getTitle() + "\", \"page\":" + pageNumber + "}";';
- PUT ' bookmarks.add(text);';
- PUT ' addBookmark(bookmarks, document, current, level + 1);';
- PUT ' current = current.getNextSibling();';
- PUT ' }';
- PUT ' }';
- PUT ' }';
- PUT 'ENDSUBMIT;';
- PUT 'QUIT;';
-
- RUN;
- %INCLUDE _rdbkpd;
-
- LIBNAME jsonCont JSON "&jsonFile";
-
- DATA &outdat(DROP=ordinal_root);
- SET jsonCont.root;
- RUN;
-
-%MEND smile_pdf_read_bookmarks;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_pdf_read_bookmarks
+%* Parameters : PDFFILE - name of PDF file with bookmarks
+%* OUTDAT - output dataset
+%* PDFBOX_JAR - path and jar file name for PDFBOX open source tool, e.g. &path/pdfbox-app-2.0.22.jar
+%*
+%* Purpose : Read PDF Bookmarks into a SAS dataset with the variables level, title and page
+%* Comment : Make sure to download PDFBOX, e.g. from here https://pdfbox.apache.org/download.html - the full "app" version
+%* Issues : "unable to resolve class" messages mean the PDFBOX is not provided correctly.
+%* "ERROR: PROCEDURE GROOVY cannot be used when SAS is in the lock down state." means that your SAS environment
+%* does not support PROC GROOVY, for this the macro cannot run the groovy code.
+%*
+%* ExampleProg: ../programs/test_smile_pdf_read_bookmarks.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-13
+%* License : MIT
+%*
+%* Reference : PDFBox contains a lot of useful functionalities (https://pdfbox.apache.org)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%smile_pdf_read_bookmarks(pdfFile = /ods_document_flat1.pdf,
+ outdat = book_flat1,
+ pdfbox_jar_path = /pdfbox-app-2.0.22.jar)
+
+%smile_pdf_read_bookmarks(pdfFile = /ods_document_noflat1.pdf,
+ outdat = book_noflat1,
+ pdfbox_jar_path = /pdfbox-app-2.0.22.jar)
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_pdf_read_bookmarks(pdfFile = , outdat = , pdfbox_jar_path = );
+
+ %LOCAL jsonFile;
+
+ FILENAME jsonFile TEMP;
+ %LET jsonFile = %SYSFUNC(PATHNAME(jsonFile));
+
+ FILENAME _rdbkpd TEMP;
+ DATA _NULL_;
+ FILE _rdbkpd LRECL=5000;
+
+ PUT 'PROC GROOVY;';
+ PUT ' ADD CLASSPATH = "' "&pdfbox_jar_path" '";';
+ PUT ' SUBMIT;';
+ PUT ;
+ PUT ' import java.io.File;';
+ PUT ' import java.io.FileWriter;';
+ PUT ' import java.io.IOException;';
+ PUT ' import java.io.PrintWriter;';
+ PUT ' import java.util.ArrayList;';
+ PUT ;
+ PUT ' import org.apache.pdfbox.pdmodel.PDDocument;';
+ PUT ' import org.apache.pdfbox.pdmodel.PDPage;';
+ PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;';
+ PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;';
+ PUT ' import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode;';
+ PUT ;
+ PUT ' public class PDFReadBookmarks {';
+ PUT ;
+ PUT ' public static void main(String[] args) throws IOException {';
+ PUT ' ArrayList aBookmarks = new ArrayList();';
+ PUT ;
+ PUT ' // Read the PDF document and investigate bookmarks into a list (JSON formatted)';
+ PUT ' PDDocument document = PDDocument.load(new File("' "&pdffile" '"));';
+ PUT ' PDDocumentOutline outline = document.getDocumentCatalog().getDocumentOutline();';
+ PUT ' addBookmark(aBookmarks, document, outline, 1);';
+ PUT ' document.close();';
+ PUT ;
+ PUT ' // Print bookmark information into a file';
+ PUT ' FileWriter fileWriter = new FileWriter("' "&jsonFile" '");';
+ PUT ' PrintWriter printWriter = new PrintWriter(fileWriter);';
+ PUT ' printWriter.print(aBookmarks);';
+ PUT ' printWriter.close();';
+ PUT ' }';
+ PUT ;
+ PUT ' static public void addBookmark(ArrayList bookmarks, PDDocument document, PDOutlineNode bookmark, int level) throws IOException';
+ PUT ' {';
+ PUT ' PDOutlineItem current = bookmark.getFirstChild();';
+ PUT ' while (current != null)';
+ PUT ' {';
+ PUT ' PDPage currentPage = current.findDestinationPage(document);';
+ PUT ' Integer pageNumber = document.getDocumentCatalog().getPages().indexOf(currentPage) + 1;';
+ PUT ' String text = "\n{\"level\":" + level + ", \"title\":\"" + current.getTitle() + "\", \"page\":" + pageNumber + "}";';
+ PUT ' bookmarks.add(text);';
+ PUT ' addBookmark(bookmarks, document, current, level + 1);';
+ PUT ' current = current.getNextSibling();';
+ PUT ' }';
+ PUT ' }';
+ PUT ' }';
+ PUT 'ENDSUBMIT;';
+ PUT 'QUIT;';
+
+ RUN;
+ %INCLUDE _rdbkpd;
+
+ LIBNAME jsonCont JSON "&jsonFile";
+
+ DATA &outdat(DROP=ordinal_root);
+ SET jsonCont.root;
+ RUN;
+
+%MEND smile_pdf_read_bookmarks;
diff --git a/macros/smile_replace_in_text_files.sas b/macros/smile_replace_in_text_files.sas
new file mode 100644
index 0000000..33a7ee0
--- /dev/null
+++ b/macros/smile_replace_in_text_files.sas
@@ -0,0 +1,146 @@
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_replace_in_text_files
+%* Parameters : INPATH - input directory (no quotes)
+%* OUTPATH - output directory, if same as INPATH, files are overwritten (no quotes)
+%* REPLACE_FROM - text which should be replaced (with quotes)
+%* REPLACE_WITH - text that should newly be added (with quotes)
+%* FILETYPE - extension of file types which should be processed, e.g. sas or txt (optional)
+%*
+%* Purpose : Replace text from all files contained in a folder with a different text
+%*
+%* ExampleProg: ../programs/test_smile_replace_in_text_files.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-03-05
+%* License : MIT
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%* replace the default root path in all example files;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/programs,
+ outpath = /home/u49641771/smile/programs,
+ replace_from = '%LET root = /folders/myshortcuts/git/SMILE-SmartSASMacros;',
+ replace_to = '%LET root = /home/u49641771/smile;');
+
+%* replace all tabls with four spaces;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/programs,
+ outpath = /home/u49641771/smile/programs/blub,
+ replace_from = '09'x,
+ replace_to = ' ');
+
+%* replace all zero numbers with x in the output;
+%smile_replace_in_text_files(
+ inpath = /home/u49641771/smile/results,
+ outpath = /home/u49641771/smile/results/mod,
+ replace_from = '0',
+ replace_to = 'x',
+ filetype = lst);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_replace_in_text_files(
+ inpath = ,
+ outpath = ,
+ replace_from = ,
+ replace_to = ,
+ filetype =
+);
+
+ %LOCAL macro;
+ %LET macro = &sysmacroname;
+
+ %IF %SYSFUNC(FILEEXIST("&inpath")) < 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - INPATH folder does not exist: &inpath.;
+ %RETURN;
+ %END;
+
+ %IF %SYSFUNC(FILEEXIST("&outpath")) < 1
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - OUTPATH folder does not exist: &inpath.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&replace_from) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - REPLACE_FROM must be provided.;
+ %RETURN;
+ %END;
+
+ %IF %LENGTH(&replace_to) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - REPLACE_FROM must be provided.;
+ %RETURN;
+ %END;
+
+ %* read all files (ignore those without dot (folders));
+ FILENAME myPath "&inpath";
+ DATA _dir (KEEP=filename);
+ ATTRIB filename FORMAT=$200.;
+ list = DOPEN('myPath');
+ IF list > 0
+ THEN DO;
+ DO i = 1 to dnum(list);
+ filename = TRIM(DREAD(list,i));
+ %IF %LENGTH(&filetype) > 0
+ %THEN %DO;
+ IF INDEX(UPCASE(filename),"%UPCASE(.&filetype)") > 0
+ THEN OUTPUT;
+ %END;
+ %ELSE %DO;
+ IF INDEX(filename,".") > 0
+ THEN OUTPUT;
+ %END;
+ END;
+ END;
+ rc = CLOSE(list);
+ RUN;
+ FILENAME myPath;
+
+ %* re-create all files using a TRANWRD to perform replacement;
+ DATA _NULL_;
+ SET _dir;
+ ATTRIB cmd FORMAT=$1000.;
+ ATTRIB from FORMAT=$1000.;
+ ATTRIB to FORMAT=$1000.;
+ from = SYMGET('replace_from');
+ to = SYMGET('replace_to');
+ %* create three filenames (input, output, temporary in-between (needed if input=output));
+ CALL EXECUTE('FILENAME _rep_tmp TEMP;');
+ cmd = "FILENAME _rep_in '&inpath/" || STRIP(filename) || "';";
+ CALL EXECUTE(cmd);
+ cmd = "FILENAME _rep_out '&outpath/" || STRIP(filename) || "';";
+ CALL EXECUTE(cmd);
+ %* replace texts and create temporary file;
+ CALL EXECUTE('DATA _NULL_;');
+ CALL EXECUTE(' INFILE _rep_in LRECL=2000 END=_eof;');
+ CALL EXECUTE(' FILE _rep_tmp LRECL=2000;');
+ CALL EXECUTE(' ATTRIB line FORMAT=$2000.;');
+ CALL EXECUTE(' INPUT;');
+ CALL EXECUTE(' line = _INFILE_;');
+ cmd = "line = TRANWRD(line," || STRIP(from) || ", " || STRIP(to) || ');';
+ PUT cmd = ;
+ CALL EXECUTE(cmd);
+ CALL EXECUTE(' IF LENGTHN(line) = 0 THEN PUT;');
+ CALL EXECUTE(' ELSE DO;');
+ CALL EXECUTE(' pos = LENGTHN(line) - LENGTHN(STRIP(line)) + 1;');
+ CALL EXECUTE(' PUT @pos line;');
+ CALL EXECUTE(' END;');
+ CALL EXECUTE('RUN;');
+ %* store temporary file as final file;
+ CALL EXECUTE('DATA _NULL_;');
+ CALL EXECUTE(" rc=FCOPY('_rep_tmp', '_rep_out');");
+ CALL EXECUTE('RUN;');
+ RUN;
+
+ PROC DATASETS LIB=WORK NOLIST;
+ DELETE _dir;
+ RUN;
+
+%MEND smile_replace_in_text_files;
diff --git a/macros/smile_url_check.sas b/macros/smile_url_check.sas
index e291a7b..2467e9f 100644
--- a/macros/smile_url_check.sas
+++ b/macros/smile_url_check.sas
@@ -1,97 +1,97 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_url_check
-%* Parameters : URL - http(s) URL which should be checked in quotes
-%* RETURN - return code variable (scope should be global)
-%* INFO - NO/YES indicator to print information to the log
-%*
-%* Purpose : Check existence of URL and store result in return code, information can optionally be printed to the log
-%* Comment : Return codes are 0 - url found, 999 - no url provided,
-%* 998 - url not provided in quotes, otherwise html-return code (e.g. 404 file not found)
-%*
-%* ExampleProg: ../programs/test_smile_url_check.sas
-%*
-%* Author : Katja Glass
-%* Creation : 2021-02-19
-%* License : MIT
-%*
-%* Reference : The idea from this macro is coming from a paper by Joseph Henry - The ABCs of PROC HTTP
-%* (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-OPTIONS NONOTES;
-%GLOBAL rc;
-%smile_url_check(url="https://github.com/phuse-org/phuse-scripts/blob/master/whitepapers/scriptathons/central/dummy.sas");
-%PUT &rc;
-%smile_url_check(url="https://github.com/phuse-org/phuse-scripts/blob/master/whitepapers/scriptathons/central/Box_Plot_Baseline.sas");
-%PUT &rc;
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_url_check(url=, return=rc, info=NO);
-
- %LOCAL macro issue;
- %LET macro = &sysmacroname;
- %LET issue = 0;
-
- %* check: URL must be provided;
- %IF %LENGTH(&url) = 0
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - URL must be provided.;
- %IF %LENGTH(&return) > 0
- %THEN %DO;
- %LET &return = 999;
- %END;
- %RETURN;
- %END;
-
- %* check: URL must be provided in quotes;
- DATA _NULL_;
- ATTRIB url FORMAT=$2000.;
- url = SYMGET('url');
- IF NOT (SUBSTR(url,1,1) IN ("'",'"') AND SUBSTR(url,LENGTH(url)) IN ("'",'"'))
- THEN DO;
- PUT "ERR" "OR: ¯o - URL must be provided in quotes.";
- %IF %LENGTH(&return) > 0
- %THEN %DO;
- CALL SYMPUT("&return", "998");
- %END;
- CALL SYMPUT("issue", "1");
- END;
- RUN;
- %IF &issue = 1
- %THEN %RETURN;
-
- %* perform URL check;
- FILENAME out TEMP;
- FILENAME hdrs TEMP;
-
- PROC HTTP URL=&url
- HEADEROUT=hdrs;
- RUN;
-
- DATA _NULL_;
- INFILE hdrs SCANOVER TRUNCOVER;
- INPUT @'HTTP/1.1' code 4. message $255.;
-
- %IF %LENGTH(&return) > 0
- %THEN %DO;
- IF code=200
- THEN CALL SYMPUT("&return", "0");
- ELSE CALL SYMPUT("&return", code);
- %END;
- %IF %UPCASE(&info) NE NO
- %THEN %DO;
- PUT "Return Code: " code;
- PUT "Return Message: " message;
- %END;
- RUN;
-
- FILENAME out;
- FILENAME hdrs;
-
-%MEND smile_url_check;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_url_check
+%* Parameters : URL - http(s) URL which should be checked in quotes
+%* RETURN - return code variable (scope should be global)
+%* INFO - NO/YES indicator to print information to the log
+%*
+%* Purpose : Check existence of URL and store result in return code, information can optionally be printed to the log
+%* Comment : Return codes are 0 - url found, 999 - no url provided,
+%* 998 - url not provided in quotes, otherwise html-return code (e.g. 404 file not found)
+%*
+%* ExampleProg: ../programs/test_smile_url_check.sas
+%*
+%* Author : Katja Glass
+%* Creation : 2021-02-19
+%* License : MIT
+%*
+%* Reference : The idea from this macro is coming from a paper by Joseph Henry - The ABCs of PROC HTTP
+%* (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+OPTIONS NONOTES;
+%GLOBAL rc;
+%smile_url_check(url="https://github.com/phuse-org/phuse-scripts/blob/master/whitepapers/scriptathons/central/dummy.sas");
+%PUT &rc;
+%smile_url_check(url="https://github.com/phuse-org/phuse-scripts/blob/master/whitepapers/scriptathons/central/Box_Plot_Baseline.sas");
+%PUT &rc;
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_url_check(url=, return=rc, info=NO);
+
+ %LOCAL macro issue;
+ %LET macro = &sysmacroname;
+ %LET issue = 0;
+
+ %* check: URL must be provided;
+ %IF %LENGTH(&url) = 0
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - URL must be provided.;
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ %LET &return = 999;
+ %END;
+ %RETURN;
+ %END;
+
+ %* check: URL must be provided in quotes;
+ DATA _NULL_;
+ ATTRIB url FORMAT=$2000.;
+ url = SYMGET('url');
+ IF NOT (SUBSTR(url,1,1) IN ("'",'"') AND SUBSTR(url,LENGTH(url)) IN ("'",'"'))
+ THEN DO;
+ PUT "ERR" "OR: ¯o - URL must be provided in quotes.";
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ CALL SYMPUT("&return", "998");
+ %END;
+ CALL SYMPUT("issue", "1");
+ END;
+ RUN;
+ %IF &issue = 1
+ %THEN %RETURN;
+
+ %* perform URL check;
+ FILENAME out TEMP;
+ FILENAME hdrs TEMP;
+
+ PROC HTTP URL=&url
+ HEADEROUT=hdrs;
+ RUN;
+
+ DATA _NULL_;
+ INFILE hdrs SCANOVER TRUNCOVER;
+ INPUT @'HTTP/1.1' code 4. message $255.;
+
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ IF code=200
+ THEN CALL SYMPUT("&return", "0");
+ ELSE CALL SYMPUT("&return", code);
+ %END;
+ %IF %UPCASE(&info) NE NO
+ %THEN %DO;
+ PUT "Return Code: " code;
+ PUT "Return Message: " message;
+ %END;
+ RUN;
+
+ FILENAME out;
+ FILENAME hdrs;
+
+%MEND smile_url_check;
diff --git a/macros/smile_url_download.sas b/macros/smile_url_download.sas
index 7347a41..b206a51 100644
--- a/macros/smile_url_download.sas
+++ b/macros/smile_url_download.sas
@@ -1,97 +1,97 @@
-%************************************************************************************************************************;
-%* Project : SMILE - SAS Macros, Intuitive Library Extension
-%* Macro : smile_url_download
-%* Parameters : URL - http(s) URL which should be checked in quotes
-%* OUTFILE - output file provided in quotes
-%* RETURN - return code variable (scope should be global)
-%* INFO - NO/YES indicator to print information to the log
-%*
-%* Purpose : Downloads a file from an URL and store it locally on OUTFILE. Additionally return code can be stored and
-%* information can optionally be printed to the log.
-%* Comment : Return codes are 0 - URL found, 999 - no URL or OUTFILE provided,
-%* 998 - URL or OUTFILE not provided in quotes, otherwise html-return code (e.g. 404 file not found)
-%*
-%* Author : Katja Glass
-%* Creation : 2021-01-04
-%* License : MIT
-%*
-%* Reference : The idea from this macro is coming from a paper by Joseph Henry - The ABCs of PROC HTTP
-%* (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf)
-%*
-%* SAS Version: SAS 9.4
-%*
-%************************************************************************************************************************;
-/*
-Examples:
-%smile_url_download(url="http://sas.cswenson.com/downloads/macros/AddFormatLib.sas",
- outfile="/folders/myshortcuts/git/sas-dev/packages/chris_sas_macros/AddFormatLib.sas",
- info=NO,
- return=);
-*/
-%************************************************************************************************************************;
-
-%MACRO smile_url_download(url=, outfile=, info=NO, return=);
-
- %LOCAL macro issue;
- %LET macro = &sysmacroname;
- %LET issue = 0;
-
- %* check: URL and OUTFILE must be provided;
- %IF %LENGTH(&url) = 0 OR %LENGTH(&outfile)
- %THEN %DO;
- %PUT %STR(ERR)OR: ¯o - URL and OUTFILE must be provided.;
- %IF %LENGTH(&return) > 0
- %THEN %LET &return = 999;
- %RETURN;
- %END;
-
- %* check: URL and OUTFILE must be provided in quotes;
- DATA _NULL_;
- ATTRIB url FORMAT=$2000.;
- ATTRIB outfile FORMAT=$2000.;
- url = SYMGET('url');
- IF NOT (SUBSTR(url,1,1) IN ("'",'"') AND SUBSTR(url,LENGTH(url)) IN ("'",'"'))
- THEN DO;
- PUT "ERR" "OR: ¯o - URL must be provided in quotes.";
- %IF %LENGTH(&return) > 0
- %THEN CALL SYMPUT("&return", "998");
- CALL SYMPUT("issue", "1");
- END;
- outfile = SYMGET('outfile');
- IF NOT (SUBSTR(outfile,1,1) IN ("'",'"') AND SUBSTR(outfile,LENGTH(outfile)) IN ("'",'"'))
- THEN DO;
- PUT "ERR" "OR: ¯o - OUTFILE must be provided in quotes.";
- %IF %LENGTH(&return) > 0
- %THEN CALL SYMPUT("&return", "998");
- CALL SYMPUT("issue", "1");
- END;
- RUN;
- %IF &issue = 1
- %THEN %RETURN;
-
- FILENAME out &outfile;
- FILENAME hdrs TEMP;
-
- PROC HTTP URL=&url
- OUT=out
- HEADEROUT=hdrs;
- RUN;
-
- DATA _NULL_;
- INFILE hdrs SCANOVER TRUNCOVER;
- INPUT @'HTTP/1.1' code 4. message $255.;
-
- %IF %LENGTH(&return) > 0
- %THEN %DO;
- IF code=200
- THEN CALL SYMPUT("&return", "0");
- ELSE CALL SYMPUT("&return", code);
- %END;
- %IF %UPCASE(&info) NE NO
- %THEN %DO;
- PUT "Return Code: " code;
- PUT "Return Message: " message;
- %END;
- RUN;
-
-%MEND smile_url_download;
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Macro : smile_url_download
+%* Parameters : URL - http(s) URL which should be checked in quotes
+%* OUTFILE - output file provided in quotes
+%* RETURN - return code variable (scope should be global)
+%* INFO - NO/YES indicator to print information to the log
+%*
+%* Purpose : Downloads a file from an URL and store it locally on OUTFILE. Additionally return code can be stored and
+%* information can optionally be printed to the log.
+%* Comment : Return codes are 0 - URL found, 999 - no URL or OUTFILE provided,
+%* 998 - URL or OUTFILE not provided in quotes, otherwise html-return code (e.g. 404 file not found)
+%*
+%* Author : Katja Glass
+%* Creation : 2021-01-04
+%* License : MIT
+%*
+%* Reference : The idea from this macro is coming from a paper by Joseph Henry - The ABCs of PROC HTTP
+%* (https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3232-2019.pdf)
+%*
+%* SAS Version: SAS 9.4
+%*
+%************************************************************************************************************************;
+/*
+Examples:
+%smile_url_download(url="http://sas.cswenson.com/downloads/macros/AddFormatLib.sas",
+ outfile="/folders/myshortcuts/git/sas-dev/packages/chris_sas_macros/AddFormatLib.sas",
+ info=NO,
+ return=);
+*/
+%************************************************************************************************************************;
+
+%MACRO smile_url_download(url=, outfile=, info=NO, return=);
+
+ %LOCAL macro issue;
+ %LET macro = &sysmacroname;
+ %LET issue = 0;
+
+ %* check: URL and OUTFILE must be provided;
+ %IF %LENGTH(&url) = 0 OR %LENGTH(&outfile)
+ %THEN %DO;
+ %PUT %STR(ERR)OR: ¯o - URL and OUTFILE must be provided.;
+ %IF %LENGTH(&return) > 0
+ %THEN %LET &return = 999;
+ %RETURN;
+ %END;
+
+ %* check: URL and OUTFILE must be provided in quotes;
+ DATA _NULL_;
+ ATTRIB url FORMAT=$2000.;
+ ATTRIB outfile FORMAT=$2000.;
+ url = SYMGET('url');
+ IF NOT (SUBSTR(url,1,1) IN ("'",'"') AND SUBSTR(url,LENGTH(url)) IN ("'",'"'))
+ THEN DO;
+ PUT "ERR" "OR: ¯o - URL must be provided in quotes.";
+ %IF %LENGTH(&return) > 0
+ %THEN CALL SYMPUT("&return", "998");
+ CALL SYMPUT("issue", "1");
+ END;
+ outfile = SYMGET('outfile');
+ IF NOT (SUBSTR(outfile,1,1) IN ("'",'"') AND SUBSTR(outfile,LENGTH(outfile)) IN ("'",'"'))
+ THEN DO;
+ PUT "ERR" "OR: ¯o - OUTFILE must be provided in quotes.";
+ %IF %LENGTH(&return) > 0
+ %THEN CALL SYMPUT("&return", "998");
+ CALL SYMPUT("issue", "1");
+ END;
+ RUN;
+ %IF &issue = 1
+ %THEN %RETURN;
+
+ FILENAME out &outfile;
+ FILENAME hdrs TEMP;
+
+ PROC HTTP URL=&url
+ OUT=out
+ HEADEROUT=hdrs;
+ RUN;
+
+ DATA _NULL_;
+ INFILE hdrs SCANOVER TRUNCOVER;
+ INPUT @'HTTP/1.1' code 4. message $255.;
+
+ %IF %LENGTH(&return) > 0
+ %THEN %DO;
+ IF code=200
+ THEN CALL SYMPUT("&return", "0");
+ ELSE CALL SYMPUT("&return", code);
+ %END;
+ %IF %UPCASE(&info) NE NO
+ %THEN %DO;
+ PUT "Return Code: " code;
+ PUT "Return Message: " message;
+ %END;
+ RUN;
+
+%MEND smile_url_download;
diff --git a/mkdocs.yml b/mkdocs.yml
index 9c073ac..b59dae3 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -14,6 +14,7 @@ nav:
- smile_ods_document_flat_label: smile_ods_document_flat_label.md
- smile_pdf_merge: smile_pdf_merge.md
- smile_pdf_read_bookmarks: smile_pdf_read_bookmarks.md
+ - smile_replace_in_text_files: smile_replace_in_text_files.md
- smile_url_check: smile_url_check.md
- smile_url_download: smile_url_download.md
- Example Programs:
@@ -23,6 +24,7 @@ nav:
- smile_ods_document_flat_label: test_smile_ods_document_flat_label.md
- smile_pdf_merge: test_smile_pdf_merge.md
- smile_pdf_read_bookmarks: test_smile_pdf_read_bookmarks.md
+ - smile_smile_replace_in_text_files: test_smile_replace_in_text_files.md
- smile_url_check: test_smile_url_check.md
# Style Sheet
diff --git a/programs/test_smile_ods_document_flat_label.sas b/programs/test_smile_ods_document_flat_label.sas
index 298f190..804e304 100644
--- a/programs/test_smile_ods_document_flat_label.sas
+++ b/programs/test_smile_ods_document_flat_label.sas
@@ -212,4 +212,4 @@ ODS PDF CLOSE;
ODS PDF CLOSE;
%MEND;
%do_it();
-%* Flat bookmarks are available (screenshot: screen_ods_doc_flat9.jpg);
\ No newline at end of file
+%* Flat bookmarks are available (screenshot: screen_ods_doc_flat9.jpg);
diff --git a/programs/test_smile_pdf_read_bookmarks.sas b/programs/test_smile_pdf_read_bookmarks.sas
index 92140f7..19d6b05 100644
--- a/programs/test_smile_pdf_read_bookmarks.sas
+++ b/programs/test_smile_pdf_read_bookmarks.sas
@@ -30,4 +30,4 @@ OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
outdat = book_noflat1,
pdfbox_jar_path = &root/lib/pdfbox-app-2.0.22.jar);
-%* Bookmarks and levels are stored in BOOK_NOFLAT1 (dataset: book_noflat1);
\ No newline at end of file
+%* Bookmarks and levels are stored in BOOK_NOFLAT1 (dataset: book_noflat1);
diff --git a/programs/test_smile_replace_in_text_files.sas b/programs/test_smile_replace_in_text_files.sas
new file mode 100644
index 0000000..23266e4
--- /dev/null
+++ b/programs/test_smile_replace_in_text_files.sas
@@ -0,0 +1,72 @@
+%************************************************************************************************************************;
+%* Project : SMILE - SAS Macros, Intuitive Library Extension
+%* Purpose : Example program for macro calls of %smile_replace_in_text_files
+%* Author : Katja Glass
+%* Creation : 2021-02-15
+%* SAS Version: SAS 9.4
+%* License : MIT
+%************************************************************************************************************************;
+
+%* initialize macros;
+%LET root = /folders/myshortcuts/git/SMILE-SmartSASMacros;
+OPTIONS SASAUTOS=(SASAUTOS, "&root/macros");
+OPTIONS NONOTES;
+
+%* support macro to create a text file;
+%MACRO create_text_file();
+ DATA _NULL_;
+ FILE "&root/results/temp/example.sas";
+ PUT "* This is a file created by a program to demonstrate text replacements";
+ PUT "* Created: {todayDate}";
+ PUT '%LET path = ;';
+ RUN;
+%MEND;
+
+%* support macro to print content of text file;
+%MACRO print_text_file();
+ DATA _NULL_;
+ INFILE "&root/results/temp/example.sas";
+ INPUT;
+ PUT _INFILE_;
+ RUN;
+%MEND;
+
+*************************************************************************;
+* Example 1 - replace in all sas files;
+*************************************************************************;
+
+%* create a sas file;
+%create_text_file();
+
+%* file has been created with the following content (log-output);
+%print_text_file();
+
+%* call macro to replace in all sas files;
+%smile_replace_in_text_files(
+ inpath = &root/results/temp,
+ outpath = &root/results/temp,
+ replace_from = '',
+ replace_to = 'c:\temp\myPath');
+
+%* file contains the new text c:\temp\myPath instead of ;
+%print_text_file();
+
+*************************************************************************;
+* Example 2 - replace {todayDate} in all sas files;
+*************************************************************************;
+
+%* create a sas file;
+%create_text_file();
+
+%* file has been created with the following content (log-output);
+%print_text_file();
+
+%* call macro to replace in all sas files;
+%smile_replace_in_text_files(
+ inpath = &root/results/temp,
+ outpath = &root/results/temp,
+ replace_from = '{todayDate}',
+ replace_to = "%SYSFUNC(date(),date9.)");
+
+%* file contains the new text c:\temp\myPath instead of ;
+%print_text_file();