Hello everyone,
I was requested to write a procedure that validates that the WORK library contains the requested tables with the right nomenclature, example given below:
File’s name | Name of the table in SAS |
ex_1.csv | ex_1 |
ex_2.csv | ex_2 |
ex_3.csv | ex_3 |
ex_4.csv | ex_4 |
I've created a project, then imported the 4 tables and then used the procedure below:
proc datasets library=work memtype=data;
run;
I was not able to reproduce what it was requested, but only the below:
WORK |
V9 |
C:\Users\augus\xxxx\Prc2 |
C:\Users\augus\xxxx\Prc2 |
DESKTOP-xxx\augus |
4KB |
4096 |
ex_1 | DATA | 2MB | 2023-03-03 13:45:49 |
ex_2 | DATA | 2MB | 2023-03-03 13:45:50 |
ex_3 | DATA | 2MB | 2023-03-03 13:45:50 |
ex_4 | DATA | 35MB | 2023-03-03 13:45:55 |
Then I've used the below in an attempt to remove the details from Directory, but keeping the library name:
PROC CONTENTS NOPRINT DATA=work._ALL_
OUT=WORK DETAILS DIRECTORY MEMTYPE=DATA;
RUN;
proc sort out=work
dupout=memname
nodupkey;
by memname;
run;
But I got a table with a lot of details and no file name. The table headers and (content) were:
Libname (Work), Memname (tables_names), Memlabel (empty),
Typemem, Name (a variation of tables_names), Type (1,2), Length (8...11), Varnum (2...22),
Label (empty), Format (Best, $CHAR), Formatl (2,5,11), Formatd (0), Informat (Best, $CHAR), Informl (2,5,11), Informd (0), Just (0), NPOS (16...217), NOBS (2694...133665), Engine (V9), Crdate and the list go on with no relevant info.
Only the libname and memname columns gave what I needed, is it possible to remove the rest of the columns and insert one with the original names of the files?
Thank you for the help!
You are asking for the KEEP= dataset option.
proc contents noprint data=work._all_ out=contents ;
run;
proc sort data=contents(keep=libname memname) out=members nodupkey;
by memname;
run;
If you expect SAS to automagically know which of your CSV files were read to create a specific SAS data set then you are going to be disappointed. SAS can report on the file path and name of the SAS data set but post operation procedures like DATASETS have no way of knowing what external file was read.
This will get the names of all data sets in the work library and the library name.
Proc sql; create table sets as select libname, memname from dictionary.tables where libname='WORK' and memtype='DATA' ; quit;
If you have a list of Files that were supposed to be read that list could be turned into a data set and you can attempt to match the values with the data sets. BUT that is making a lot of assumptions. Note that the Memname and Libname will be stored by SAS in uppercase in the special dictionary files that maintain metadata about your data.
You are asking for the KEEP= dataset option.
proc contents noprint data=work._all_ out=contents ;
run;
proc sort data=contents(keep=libname memname) out=members nodupkey;
by memname;
run;
Thank you @Tom !
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.