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
SAS Super FREQ
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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 656 views
  • 0 likes
  • 2 in conversation