BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
LucasW
Calcite | Level 5

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:

Directory Libref Engine Physical Name FilenameOwner NameFile SizeFile Size (bytes)
WORK
V9
C:\Users\augus\xxxx\Prc2
C:\Users\augus\xxxx\Prc2
DESKTOP-xxx\augus
4KB
4096
 # Name Member Type File Size Last Modified1234
ex_1DATA2MB2023-03-03 13:45:49
ex_2DATA2MB2023-03-03 13:45:50
ex_3DATA2MB2023-03-03 13:45:50
ex_4DATA35MB2023-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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Reeza
Super User
Maybe instead of proc datasets, you can query either dictionary.table or dictionary.column which contain the information you're looking to obtain.
ballardw
Super User

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.

Tom
Super User Tom
Super User

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;
LucasW
Calcite | Level 5

Thank you @Tom !

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 895 views
  • 1 like
  • 4 in conversation