The SAS Output Delivery System and reporting techniques

create names for multiple htms using SAS macro

Reply
Occasional Contributor
Posts: 13

create names for multiple htms using SAS macro

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!

Super User
Posts: 5,082

Re: create names for multiple htms using SAS macro

It sounds like you need more experience with macro language, to figure out what it is doing.

 

Look through your macro, with these guidelines:

 

  • Any time you see &ST (or &st) picture it as being replaced by the 4 characters 'CA'
  • Any time  you see &XST1 (or &xst1) picture it as being replaced by the 4 characters CA15

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. 

Occasional Contributor
Posts: 13

Re: create names for multiple htms using SAS macro

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?

Super User
Posts: 5,082

Re: create names for multiple htms using SAS macro

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.

SAS Super FREQ
Posts: 8,743

Re: create names for multiple htms using SAS macro

Occasional Contributor
Posts: 13

Re: create names for multiple htms using SAS macro

Thank you Cynthia.

Ask a Question
Discussion stats
  • 5 replies
  • 202 views
  • 2 likes
  • 3 in conversation