BookmarkSubscribeRSS Feed
RobertNYC
Obsidian | Level 7

Hi all--

I’m having trouble generating a macro value in a dataset I use to create a title page in a PDF.

The macro  variable is agyname:

%let agyname="Agency ABC";

So instead for the title reading “Agency ABC” the program  prints “&agyname

Below is where I create a dataset for the title page. Notice where I have written the macro variable  &agyname.

data work.title;           

drop i;

length line $200;

  do i = 1 to 6 by 1;

    line = '  ';

    output;

  end;

line = "^S={font_size=16pt}2012 Agency Regular Medical Review";

output;

line = '^S={font_size=15pt}'

       ||'&agyname^S={}';

output;

line = "^S={background=black cellheight=.5pt font_size=1pt cellpadding=0}"

       ||'                       '||"^S={}";

output;

do i = 1 to 2 by 1;

  line = ' '; output;

  end;

output;

line = '^S={font_size=13pt font_face=Arial}'

       ||'Medical Unit'

       ||'^S={}';

output;

line = '^S={font_size=13pt font_face=Arial}'

       ||"Administration "

       ||'^S={}';

output;

  do i = 1 to 2 by 1;

    line = '  ';

    output;

  end;

run;

Below is the proc report statement I use to bring in the title data for the the pdf report

proc report data=work.title noheader nowd

style={rules=none frame=void just=c

             cellspacing=0 cellpadding=4pt};

column line;

define line /

style(column)={just=c font_weight=bold

                font_face=Arial

                foreground=black};

ods pdf startpage=no;

run;

Any help is greatly appreciated!

3 REPLIES 3
Cynthia_sas
Diamond | Level 26

Hi:

  Macro variables do NOT resolve within single quotes:

line = '^S={font_size=15pt}' ||'&agyname^S={}';

so I'd suggest that you try to replace your single quotes with double quotes:

line = '^S={font_size=15pt}' || "&agyname^S={}" ;

cynthia

Tom
Super User Tom
Super User

Macro variable references do not resolve inside of single quotes.


%let agyname="Agency ABC";


So where you have :

line = '^S={font_size=15pt}'||'&agyname^S={}';


You are setting the value of the dataset variable LINE to


'^S={font_size=15pt}&agyname^S={}'


But you probably want it to instead be this value:


'^S={font_size=15pt}Agency ABC^S={}'


You already included double quotes around your macro variable's value so you can write that statement this way:


line = '^S={font_size=15pt}'||&agyname||'^S={}';


If you removed the quotes from around the value of the macro variable in your %LET statement then you would want to write the assignment statement this way:


line = '^S={font_size=15pt}'||"&agyname"||'^S={}';

Cynthia_sas
Diamond | Level 26


Oh, good eyes, Tom!

I didn't notice the double quotes on the %LET statement. Good catch!

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1194 views
  • 0 likes
  • 3 in conversation