Help using Base SAS procedures

Populate dataset with member names

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 124
Accepted Solution

Populate dataset with member names

Greetings all.  I am needing to create a dataset with only the # and name values from the output of proc datasets.  I've found lots of documents about proc contents and proc datasets, but I can't find specifically what I'm needing to do.  If I run this...

proc datasets lib=OTBR;quit;run;

I see this in the log...

                                   Member   File
                    #  Name               Type      Size   Last Modified

                    1  ONTIMESUM0  DATA     5120  12Sep12:09:42:07
                    2  ONTIMESUM1  DATA     5120  12Sep12:09:42:14
                    3  ONTIMESUM2  DATA     5120  12Sep12:09:42:20
                    4  ONTIMESUM3  DATA     5120  12Sep12:09:42:26
                    5  ONTIMESUM4  DATA     5120  12Sep12:09:42:34

What I need to do is capture the first two columns only from this output into a dataset in the same library.  I'm not sure if I should use proc contents or proc datasets.  Does anyone have any ideas?  Thank you.

Greg


Accepted Solutions
Solution
‎09-12-2012 11:05 AM
Valued Guide
Posts: 765

Re: Populate dataset with member names

hi ... I think that you want names of data sets and views (not variables within a data set), so you could try ...

proc sql;

create table datasets as

select memname as NAME, memtype as TYPE from dictionary.tables where libname eq 'SASHELP';

quit;

just use a libref on the new data set to put it in the correct location ("...output into a dataset in the same library...")

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: Populate dataset with member names

Greg,

example:

proc contents data=sashelp.class out=want (keep=varnum name) noprint;

run;

proc print data=want;run;

Sorry. I misundstood your question. I thought you wanted the variable names in a dataset.

Solution
‎09-12-2012 11:05 AM
Valued Guide
Posts: 765

Re: Populate dataset with member names

hi ... I think that you want names of data sets and views (not variables within a data set), so you could try ...

proc sql;

create table datasets as

select memname as NAME, memtype as TYPE from dictionary.tables where libname eq 'SASHELP';

quit;

just use a libref on the new data set to put it in the correct location ("...output into a dataset in the same library...")

Respected Advisor
Posts: 3,156

Re: Populate dataset with member names

Hi,

There are many ways to obtain metadata information. Like Linlin suggested, proc contents being one. You can also directly retrieve info from dictionary tables/views. One example is (using Linlin's example):

    proc sql;

create table want as

  select varnum,name from dictionary.columns where lIBNAME='SASHELP' AND MEMNAME='CLASS';QUIT;

Haikuo

Frequent Contributor
Posts: 124

Re: Populate dataset with member names

Thank you all for the tips.  I did not think of using proc sql to hit the system tables directly.  As SQL is my native language, that option is easiest for me.  Thanks again.

Greg

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 196 views
  • 6 likes
  • 4 in conversation