BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a SAS dataset that has one column and eight rows. The column is a date field and the eight rows each contain a different date. Is there a way to pull these dates into a report title automatically, for example...
"Disease Management Summary Report"
"Strategy Date(s): 3/8/2007, 4/1/2007, 5/15/2007, 5/28/2007"

Thanks!
Jackie
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi,
It sort of depends on what your definition of "automatic" is. Consider the following program:
[pre]
proc sql;
select distinct(name) into :allname separated by ', '
from sashelp.class
where sex = 'F';
quit;

%put -----## What is macro var: &allname;

ods html file='c:\temp\macro_title.html' style=sasweb;
title 'The Report For';
title2 "&allname";
proc means data=sashelp.class min mean max;
where sex='F';
var age height;
run;
ods html close;
[/pre]

The INTO, used on the SELECT clause creates a macro variable. You can use "SEPARATED BY" in order to put commas or whatever punctuation you need in the list of names (or dates). The macro variable is going to be &ALLNAME -- notice how it appears in the log when you use &ALLNAME in the %PUT statement. %PUT does not need to have quotes around the macro variable. But, the title statement string needs to be in quotes, so for &ALLNAME to be resolved it needs to be enclosed in double quotes, ON the TITLE statement,

Remember that you may need to use PUT statements in order to get formatted dates into your macro variable. This is because the date variable will be internally stored as a number -- an offset of the number of days since Jan 1, 1960.

So, you may need to do something like this:
[pre]
select distinct(datevar) format=mmddyy10. into :alldate separated by ', '
[/pre]

Good luck,
cynthia
deleted_user
Not applicable
Thank you Cynthia. I'm pretty new to SAS so your answer is a little greek to me. I will study up on Macro variables because I have only heard the term but never actually done anything with one. I will work to make sense of your coding example.

I appreaciate your help. Have a good day!
Jackie

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 1258 views
  • 0 likes
  • 2 in conversation