Published on :
Macro / System CREATION_INTERNE

Macro ls2sas - Listing Unix Files to SAS

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The script defines the %ls2sas© macro which uses the 'filename pipe' feature to execute the 'ls -1' system command. It retrieves the list of files matching the pattern provided as a parameter (filepattern) and generates a SAS© table containing the filename and a lowercase version.
Data Analysis

Type : CREATION_INTERNE


Data is dynamically generated by executing a system command (ls) and read via a PIPE.

1 Code Block
DATA STEP Data
Explanation :
Macro definition. Option saving. Use of a 'filename pipe' to execute the 'ls' command. The DATA step reads the command's output stream to populate the target table with found filenames.
Copied!
1%macro ls2sas(filepattern,dsout);
2 
3 %local savopts;
4 %let savopts=%sysfunc(getoption(NOTES));
5 
6 %IF not %LENGTH(&dsout) %THEN %let dsout=_ls2sas;
7 
8 options nonotes;
9 
10 filename _ls2sas pipe "ls -1 %sysfunc(dequote(&filepattern))";
11 
12 DATA &dsout;
13 LENGTH filename lcfname $ 200;
14 INFILE _ls2sas;
15 INPUT;
16 filename=trim(_infile_);
17 lcfname=lowcase(scan(filename,-1,"/"));
18 RUN;
19 
20 filename _ls2sas CLEAR;
21 
22 options &savopts;
23 
24%mend ls2sas;
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, Date: 23-Apr-2013, License: Public domain