Hello,
Question regarding adding a simple title to PROC DATASETS;
I'm on Base 9.4.
4 simple steps to get to my question below.
1) clear out all previous results and titles for a 'clean slate'
/* clear out results */
dm 'odsresults;clear';
/* Using TITLE without arguments cancels all existing titles*/
title;
2) 'print' the title to verify it is cleared /*log: No observations in data set SASHELP.VTITLE.*/
/* print the current title*/
proc print data=Sashelp.VTitle; run;
3) add a new title and print to verify
/* add a new title*/
title 'reset';
/* print the current title*/
proc print data=Sashelp.VTitle; run;
4) run a simple PROC DATASETS on the default library WORK and add a title statement
(fyi: there are data sets in WORK)
proc datasets;
title 'proc datasets - Work';
quit;
OBSERVATION:
The first time I run steps 1-4 above:
The title showing on top of the 'Directory Info. + Library Members' output is "reset" (the 'old' title)
However: The second time I run just step 4):
The title shows "proc datasets - Work" as I would have expected the first time around
QUESTION:
The TITLE statement does not need a run; correct ? ... I tried it with a run; + quit; and no difference.
I do understand that PROC DATASETS only needs quit; (unless one wants to add run; as part of run groups)
So ... what might be the issue that prevents TITLE from being 'recognized the first time around' within the PROC DATASETS procedure + TITLE statement ?
greatly appreciate any insight
Many thanks for all the replies. Very helpful. Especially the observations about "There is no proc datasets option for title" and "step boundaries" (a good general practice)
Of course ... I now see said the blind man.
I have summarized the responses into a 'pseud-method' as follows (to include PROC CONTENTS and a subordinate CONTENTS statement within PROC DATASETS) .
I realize this is fairly basic here but I like the KISS approach when things go astray in my understanding.
I'm always open to further insight from the experts.
1) Clean the slate
/* clear out results */
dm 'odsresults;clear';
/* Using TITLE without arguments cancels all existing titles*/
title;
/* "print" the current title to confirm cleared */
proc print data=Sashelp.VTitle; run;
2)
Within PROC DATASETS, there is apparently no TITLE 'option' or TITLE 'statement'
Therefore, we need apply the TITLE **global statement** outside of PROC DATASETS
** When we run a simple PROC DATASETS, the previously defined TITLE global statement is applied to the output 'automatically'
** This I did not know .. and was the crux of the issue I was observing.
>>> (Output is: Directory Information + Library Members)
title 'proc datasets - Work Library ';
run;
proc datasets;
quit;
3)
Within PROC CONTENTS, use of a subordinate TITLE statement IS apparently OK
When we run a simple PROC CONTENTS, the TITLE statement (as defined within the procedure) is applied to the output
>> (Output is: Attributes + Engine/Host Dependent Information + Alphabetic List of Variables and Attributes)
proc contents data=work.data_test_1;
title 'proc contents - Work.data_test_1 Data Set ';
run;
4) We can then combine the PROC DATASETS procedure with a CONTENTS subordinate statement
(not that we necessarily want or need to see 'Library Level contents' via PROC DATASETS at the same time as 'Data Set Level'
contents via a CONTENTS statement but a good exercise for clarity .. so says I)
title 'proc datasets - Work Library';
run;
proc datasets lib=WORK memtype=data;
contents data=WORK.DATA_TEST_1;
title 'contents - Work.DATA_TEST_1 Data Set';
run;
quit;
Not 100% sure ... title-statement in proc datasets is executed after proc datasets started writing output. When you execute the 4th step again the title-statement from the last call is still active and thus the expected title is displayed.
About your observation that "The TITLE statement does not need a run; correct ?"
While that is correct, there may be problems with step boundaries (to which the previous reply alluded).
It is best to always use a RUN; statement following a TITLE statement to insure that the TITLE statement actually executes where you think it will execute. This is especially important when -- as you do here -- you are using "TITLE ; " to clear all previous titles.
While this may not be the exact issue you have here (i.e., step boundary control), it is a good habit to have.
Steve
Put title statements outside the procedure. There is no proc datasets option for title, so it should not be there. Always separate out bits unless absolutely needed, e.g:
title 'proc datasets - Work'; proc datasets; run;
If your code is as shown I suspect it's a timing issue. The title statement is after your PROC DATASETS so it's not available when the PROC starts, but is available for the next run. To clear all title statements you use your step #1 method and place your title ahead of your PROC. A lot of the demo code shows in it various places, but in general, I find before the proc is the best place to not have issues like this.
If you need more control over when it's outputted, PROC ODSTEXT allows some of that.
Many thanks for all the replies. Very helpful. Especially the observations about "There is no proc datasets option for title" and "step boundaries" (a good general practice)
Of course ... I now see said the blind man.
I have summarized the responses into a 'pseud-method' as follows (to include PROC CONTENTS and a subordinate CONTENTS statement within PROC DATASETS) .
I realize this is fairly basic here but I like the KISS approach when things go astray in my understanding.
I'm always open to further insight from the experts.
1) Clean the slate
/* clear out results */
dm 'odsresults;clear';
/* Using TITLE without arguments cancels all existing titles*/
title;
/* "print" the current title to confirm cleared */
proc print data=Sashelp.VTitle; run;
2)
Within PROC DATASETS, there is apparently no TITLE 'option' or TITLE 'statement'
Therefore, we need apply the TITLE **global statement** outside of PROC DATASETS
** When we run a simple PROC DATASETS, the previously defined TITLE global statement is applied to the output 'automatically'
** This I did not know .. and was the crux of the issue I was observing.
>>> (Output is: Directory Information + Library Members)
title 'proc datasets - Work Library ';
run;
proc datasets;
quit;
3)
Within PROC CONTENTS, use of a subordinate TITLE statement IS apparently OK
When we run a simple PROC CONTENTS, the TITLE statement (as defined within the procedure) is applied to the output
>> (Output is: Attributes + Engine/Host Dependent Information + Alphabetic List of Variables and Attributes)
proc contents data=work.data_test_1;
title 'proc contents - Work.data_test_1 Data Set ';
run;
4) We can then combine the PROC DATASETS procedure with a CONTENTS subordinate statement
(not that we necessarily want or need to see 'Library Level contents' via PROC DATASETS at the same time as 'Data Set Level'
contents via a CONTENTS statement but a good exercise for clarity .. so says I)
title 'proc datasets - Work Library';
run;
proc datasets lib=WORK memtype=data;
contents data=WORK.DATA_TEST_1;
title 'contents - Work.DATA_TEST_1 Data Set';
run;
quit;
Several things.
First, mark the person who answered your question as Correct, not your own response.
Second, step 1 does not do anything, bin it.
Third, do not put a run; after each title, that makes no sense. Run is there to finish procedures or datastep, title statement is not a procedure or datastep.
Step 4 seems a bit over the top, if you want a contents printed then:
title "abc"; proc contents data=work.data_test_1; run;
I.e. use the procedure for the task (and avoid coding in upper case).
Here is an example of using the TITLE Statement in Proc DATASETS, changing the title with each iteration within the single proc. The RUN; Statement following each title insures that the execution is tied to the statement before it, not after it, thus removing some ambiguity.
proc datasets library=sashelp nolist ;
contents data=burrows short ;
title burrows ;
run ;
contents data=cars short ;
title cars ;
run ;
quit ;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.