I would like to name the title of a html output using a sas macro that will run with a do loop for multiple iterations in SAS 9.4:
The current code is %macro test (st,xst1);
.....
%mend test;
followed by, e.g., %test ('CA',CA15);
run;
The dataset where the table (in HTML format) will be output has the following where statement:
where statefip IN (&st);
There is a year variable where there are observations with '15 values. Is there a way that I can draw this information out as a macro variable to apply for all files?
I am confused about the logic behind "xst1".
Thank you in advance for any comments and suggestions!
It sounds like you need more experience with macro language, to figure out what it is doing.
Look through your macro, with these guidelines:
Whatever SAS program results from those text substitutions, that is the program that is running.
Obviously, there is more to macro language than this. But that's a good starting point.
Thank you! Follow-up question: Does single quotes or double quotes matter for 'CA'?
I have been going through past articles from Art Carpenter and think that his macro reference would help for this and other tasks. Are there any other references that I can read up on?
Single vs. double quotes in 'CA' probably make no difference. It depends on what the SAS statement looks like after substituting those 4 characters for &ST.
As a general rule, single vs. double quotes make a big difference when referring to a macro variable. Single quotes suppress all macro activity. So:
"&xst1" will resolve and become "CA15"
But:
'&xst1' will not resolve and will remain '&xst1'
There are dozens of papers out there on macro language. Art's book is good, but you can get started today with a little searching without having to wait for a book to arrive.
Thank you Cynthia.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.