Hi All,
I need to create a csv file for each of the dataset present under a library, having the data of proc content output of each dataset.
A macro will solve this, i am able to get the list the dataset with:
proc sql;
create table columns as
select distinct(memname) as table_name
from dictionary.columns
where libname = 'WRK'
;
quit;
but how to proceed to read all the file names and fetch them to generate a csv having their proc contents is what i am stuck with...
Thanks in advance!!
When you read from the sashelp tables, you can specify the filevar= option in the file statement and then dynamically assign the output filename from the table name in the input dataset. This way you can do everything in a single data step.
ie
data _null_;
set sashelp.vcolumn (where=(libname="YOURLIB"));
by memname;
if first.memname then outfilename = '$HOME/desc_' !! trim(memname) !! '.csv';
file "dummy.dat" filevar=outfilename dlm=',';
put name type length;
run;
You're probably better off reading the metadata from sashelp.vtable and sashelp.vcolumn.
Reading the metadata is not the issue, but reading it and putting it into a csv file as a loop for all the dataset within a library is the issue. A separate csv file needs to be created for the metadata of each dataset
When you read from the sashelp tables, you can specify the filevar= option in the file statement and then dynamically assign the output filename from the table name in the input dataset. This way you can do everything in a single data step.
ie
data _null_;
set sashelp.vcolumn (where=(libname="YOURLIB"));
by memname;
if first.memname then outfilename = '$HOME/desc_' !! trim(memname) !! '.csv';
file "dummy.dat" filevar=outfilename dlm=',';
put name type length;
run;
Ups, missed to correct that before posting.
Should be
file dummy filevar=outfilename dlm=',';
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.