lsfp2sas Macro - Listing Unix/Linux files into SAS

This code is also available in: Deutsch Español Français
Difficulty Level
Beginner
Published on :
Attention : This code requires administrator privileges.
The `lsfp2sas©` macro uses the `filename pipe` method to execute a Unix shell command (`for` loop on the file pattern). It captures the standard output of this command to create a SAS© dataset containing the full file path (`filename`) and the filename alone in lowercase (`lcfname`). It manages SAS© options (NOTES) to avoid cluttering the log.
Data Analysis

Type : EXTERNE


Data comes from the operating system's file system tree (shell command executed via Pipe).

1 Code Block
DATA STEP Data
Explanation :
Macro definition. Saves options, defines a PIPE fileref executing a shell command to list files, and a Data step to read the stream returned by the command and create the output table.
Copied!
1%macro lsfp2sas(filepattern,dsout);
2 
3 %local savopts;
4 %let savopts=%sysfunc(getoption(NOTES));
5 
6 %IF not %LENGTH(&dsout) %THEN %let dsout=_lsfp2sas;
7 
8 options nonotes;
9 
10 filename _lsfp pipe
11 "for fn in %sysfunc(dequote(&filepattern)) ; do echo $fn ; done";
12 
13 DATA &dsout;
14 LENGTH filename $ 300 lcfname $ 200;
15 INFILE _lsfp;
16 INPUT;
17 filename=trim(_infile_);
18 lcfname=lowcase(scan(filename,-1,"/"));
19 RUN;
20 
21 filename _lsfp CLEAR;
22 
23 options &savopts;
24 
25%mend lsfp2sas;
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 : Author: Roland Rashleigh-Berry. Public domain software.


Related Documentation

Aucune documentation spécifique pour cette catégorie.