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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 964 views
  • 2 likes
  • 3 in conversation