Published on :
Macro EXTERNE

dsc_echofile_tolog Macro

This code is also available in: Deutsch Español Français
This macro takes a space-separated list of filerefs as input. For each fileref, it checks if it is valid and associated with an existing file. If so, it uses a DATA _NULL_ step to read the file line by line (with a maximum length of 32767 characters) and write the content to the SAS© log. It is primarily used for debugging or to keep a trace of external configuration/log files in the SAS© execution report.
Data Analysis

Type : EXTERNE


The macro reads data from external files identified by the filerefs passed as parameters ('fileRefs' argument).

1 Code Block
DATA STEP
Explanation :
Macro definition. It loops through the list of 'fileRefs', checks their existence via %sysfunc(fileref(...)), then executes a DATA STEP _NULL_ to read the file content (infile) and write it to the log (put).
Copied!
1%macro dsc_echofile_tolog(fileRefs=);
2 
3 /* echo the file contents to log if file exists */
4 %IF %LENGTH(&fileRefs) > 0 %THEN
5 %DO;
6 %let i=1;
7 %DO %while (%scan(&fileRefs,&i,' ') ne );
8 %let fileRef=%scan(&fileRefs,&i);
9 /* if the fileref & its associated file exists? */
10 %IF %sysfunc(fileref(&fileRef)) = 0 %THEN
11 %DO;
12 DATA _null_;
13 LENGTH linetxt $32767;
14 IF _n_ = 1 THEN
15 DO;
16/* fileHeader=sasmsg("&msg_dset","_cxa_norm_19_note","noquote","&fileRef");*/
17/* put fileHeader;*/
18 END;
19 INFILE &fileRef. LENGTH=reclen ;
20 INPUT linetxt $varying32767. reclen ;
21 put linetxt;
22 RUN;
23 %END;
24 %let i=%eval(&i+1);
25 %END;/* %do %while */
26 %END;/*%if %length(&fileRefs)*/
27%mend;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright 2020, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.