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

I am trying to put the outputput from PROC DATASETS into a sas datset. For example

ods trace on;
proc datasets library=work memtype=catalog;
run;
quit;

WeiChen_0-1780596439688.png

and in log i see

Output Added:
-------------
Name: Members
Label: Library Members
Template: Base.Datasets.Members
Path: Datasets.Members
-------------

 

But when try us ODS OUTPUT (or SELECT), ODS thinks output not there:

proc datasets library=work memtype=catalog;
ods output Members= MyMembers;
run;
quit;

WARNING: Output 'Members' was not created. Make sure that the output object name, label, or path
is spelled correctly. Also, verify that the appropriate procedure options are used to
produce the requested output object. For example, verify that the NOPRINT option is not
used.

 

I know some statements in PROC DATASETS have OUT= optins, like the CONTENTS stmt. but how can i get this table in a dataset? i dont see option to create output and ODS OUTPUT not working. Im on sas 9.4 latest.

 

I found other questionsm similar to mine:
https://communities.sas.com/t5/SAS-Procedures/Get-a-list-of-dataset-names-in-a-directory-library/m-p... 

https://communities.sas.com/t5/SAS-Procedures/Output-from-Proc-Datasets-as-a-data-file/m-p/489259#M7...

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I agree with Quentin and Tom. An ODS SELECT/OUTPUT statement must go before the statement that generates the table (or graph). In this case, it is the PROC DATASETS statement itself that creates the output. Run this example WITHOUT any RUN or QUIT statement:

data class1 class2;
  set sashelp.class(obs=3);
run;
ods trace on;
proc datasets lib=work memtype=data;

Even though there is no RUN or QUIT statement, you can see from the ODS trace statement that the output is created.

 

I was not aware of this behavior. In my 2024 article about interactive procedures (Interactive procedures in SAS - The DO Loop), I stated the following information from the PROC DATASETS documentation:
The interactive nature of PROC DATASETS is a different from other SAS procedures. The documentation states that it supports RUN-group processing, but "the DATASETS procedure supports four types of RUN groups.... Some statements in PROC DATASETS act as implied RUN statements because they cause the RUN group preceding them to execute."

 

I have boldfaced the statement that applies in this case. When I wrote the article, I don't think I fully appreciated what that boldfaced statement was telling us.

View solution in original post

7 REPLIES 7
Quentin
Super User

I'm surprised- it works if the ODS OUTPUT statement comes before the PROC, but not inside.  I typically like them before the PROC, but I don't think I've seen a case where they didn't work inside the PROC.

 

1    ods output Members= MyMembers;
2    proc datasets library=work memtype=catalog;
3    run;

NOTE: The data set WORK.MYMEMBERS has 2 observations and 5 variables.
4    quit;


5
6
7    proc datasets library=work memtype=catalog;
8    ods output Members= MyMembers;
9    run;

10   quit;

WARNING: Output 'Members' was not created.  Make sure that the output object name, label, or path is spelled correctly.  Also,
         verify that the appropriate procedure options are used to produce the requested output object.  For example, verify that
         the NOPRINT option is not used.
The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
Tom
Super User Tom
Super User

You need to execute the ODS OUTPUT statement before the statement that produces the output executes.

 

PROC DATASETS is an "interactive" procedure, like PROC GLM or PROC SQL.  It can run many different commands before it exits, which is why you need a QUIT statement instead of a RUN statement to mark the end of the step.

 

In this case the output is generated by the PROC statement itself, so the ODS OUTPUT statement must come before the PROC statement.

WeiChen
Obsidian | Level 7

In interactive procedures I thought the ODS statemtne had to come before the quit. See @Rick_SAS blog https://blogs.sas.com/content/iml/2011/12/12/sas-tip-put-ods-statements-inside-procedures.html

but quntin exampole shows proc datasets wierdly different.

Tom
Super User Tom
Super User

The key thing is when the code EXECUTES.  Normally it executes a block of statements when it sees a RUN statement.  But some statements, like PROC SQL statements, execute immediately.

 

Try adding ODS TRACE OFF statement it various points and see when it stops listing the generated data.

data class1 class2;
  set sashelp.class(obs=3);
run;
ods trace on;
proc datasets lib=work memtype=data;
ods trace off;
contents data=work.class1 ;
run;
quit;

Personally I always code the ODS OUTPUT statement before the PROC statement.  That is just much clearer to me than mixing GLOBAL statements into the middle of step.  Just make sure that you have explicitly ended the preceding step.

Quentin
Super User

I thought of Rick's blog when I read this as well.  Seems like the behavior of  PROC DATASETS supports the position of Otis Outside.  https://blogs.sas.com/content/iml/2013/04/08/pointcounterpoint-ods-select.html

 

And I agree with Tom's diagnosis.  It looks like the Members output object is being created by the PROC DATASETS statement itself.  If you add a CONTENTS statement, it will produce the Attributes object, and you can place the ODS statement to output that after the CONTENTS statement (but before the run).

 

1    proc datasets library=work memtype=catalog;
2    contents;
3    ods output members=MyMembers Attributes=MyAttributes ;
4    run;

NOTE: The data set WORK.MYATTRIBUTES has 10 observations and 7 variables.
5    quit;

WARNING: Output 'members' was not created.  Make sure that the output object name, label, or path is spelled correctly.  Also,
         verify that the appropriate procedure options are used to produce the requested output object.  For example, verify that
         the NOPRINT option is not used.
The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
Rick_SAS
SAS Super FREQ

I agree with Quentin and Tom. An ODS SELECT/OUTPUT statement must go before the statement that generates the table (or graph). In this case, it is the PROC DATASETS statement itself that creates the output. Run this example WITHOUT any RUN or QUIT statement:

data class1 class2;
  set sashelp.class(obs=3);
run;
ods trace on;
proc datasets lib=work memtype=data;

Even though there is no RUN or QUIT statement, you can see from the ODS trace statement that the output is created.

 

I was not aware of this behavior. In my 2024 article about interactive procedures (Interactive procedures in SAS - The DO Loop), I stated the following information from the PROC DATASETS documentation:
The interactive nature of PROC DATASETS is a different from other SAS procedures. The documentation states that it supports RUN-group processing, but "the DATASETS procedure supports four types of RUN groups.... Some statements in PROC DATASETS act as implied RUN statements because they cause the RUN group preceding them to execute."

 

I have boldfaced the statement that applies in this case. When I wrote the article, I don't think I fully appreciated what that boldfaced statement was telling us.

WeiChen
Obsidian | Level 7

thanks quentin, tom and rick! 

 

I Am still very upset SAS remove interactive mode from sas studio and ODA. If you havent voted to ask sas to return thsi funtion please upvote at

Restore Interactive Perspective in SAS Studio - SAS Support Communities

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 226 views
  • 8 likes
  • 4 in conversation