BookmarkSubscribeRSS Feed
tipscode
Obsidian | Level 7

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!

5 REPLIES 5
Astounding
PROC Star

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. 

tipscode
Obsidian | Level 7

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?

Astounding
PROC Star

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.

tipscode
Obsidian | Level 7

Thank you Cynthia.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1798 views
  • 2 likes
  • 3 in conversation