Desktop productivity for business analysts and programmers

Automatically pulling in SAS dataset variables as part of a report title

Reply
N/A
Posts: 0

Automatically pulling in SAS dataset variables as part of a report title

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
SAS Super FREQ
Posts: 8,721

Re: Automatically pulling in SAS dataset variables as part of a report title

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
N/A
Posts: 0

Re: Automatically pulling in SAS dataset variables as part of a report title

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
Ask a Question
Discussion stats
  • 2 replies
  • 112 views
  • 0 likes
  • 2 in conversation