08-02-2017 11:20 AM
Hi...I have about 100 text files stored in a directory that vary in size and in the number variables/fields within each text file. The names of each text file vary with no common pattern to the names. I would like to extract information about each field within each text file such as Field name, type, length, etc similiar to the results obtained from using PROC CONTENT. Is there an efficient way to do this without having to run the PROC CONTENT procedure 100 times? Thanks.
08-02-2017 11:29 AM
Using term "text file" with "proc contents" means yo have a library (=directory) with sas datasets.
You can use either:
proc sql; select * from distionary.columns where libname ='LIBNAME' ; /* replace to your libname in capital leters */ quit;
data contents; set sashelp.columns(where=(libname='LIBNAME')); run;
each of them is equivalent to run proc contents on all datasets in that library.
Tha names of variables in output may differ between the two methods.
08-02-2017 12:46 PM - edited 08-02-2017 12:47 PM
Text files do not normally have information on type or length. Typically text files are either in some previously defined format or perhaps they are CSV or other delimited files in which case the only metadata they have is the variable names in the first line.
How are currently converting those files into datasets?
If they really are delimited text files then perhaps you could write code to read the header lines to find the variable names and position?
data varnames; length filename filen $200 column 8 varname $32 ; infile 'my directory/*' dsd filename=filen eov=eov column=cc length=len truncover; input @; filename=filen; if _n_=1 or eov then do column=1 by 1 until( cc > len) ; input varname @ ; output; end; eov=0; run;