BookmarkSubscribeRSS Feed
steen_soeskov_sof_kk_dk
Calcite | Level 5

Hi

I have a problem with an apostrophe in a title statement.

 

%macro pdf(name);

options orientation=landscape;

ods noresults;

ods pdf file="c:\School 2019.pdf";

ods escapechar='^';

 

title "";

 

ods pdf text="^S={just=c fontweight=bold font_size=10} School 2019.";

 

ods pdf text="^S={fontweight=bold font_size=5} Name: &name.";

ods pdf text="^n";

 

PROC REPORT DATA=work.fravaer LS=158 PS=97  SPLIT="/" CENTER missing nowd;

COLUMNS name;

DEFINE name / display 'Elevens navn' style(column header)=[font_weight=bold];

RUN; 

ods pdf close;

%mend pdf;

%pdf(O'Leary);

 

Message in LOG:

WARNING: The quoted string currently being processed has become more than 262 characters long. You may have unbalanced quotation
marks.

6 REPLIES 6
ed_sas_member
Meteorite | Level 14

Hi @steen_soeskov_sof_kk_dk ,

 

You should use a macro quoting function to avoid this kind of issue -> %str() should work, with also a % before the quotation mark as it is usually used by pair.

 

%pdf(O%str(%')Leary);
/* or */
%pdf(%str(O%'Leary));
steen_soeskov_sof_kk_dk
Calcite | Level 5

Hi 

It was a good solution, if there is one person in the macro

But I use a dataset til make the macroes to the pdf files.

 

I tried to make the name with %str(%') as a "middlename", but the program translate it to '

data test;

 set test;

apostrophe = index(name,"'");
if apostrophe > 0 then do;

name = substr(name,1,apostrof-1) !! %str(%') !! substr(name,apostrof+1);
end;

run;

 

I have also tried med single quotes and double quotes around %str(%') 

steen_soeskov_sof_kk_dk
Calcite | Level 5

Hi

If I make name in my data step, I will still have a apostrophe ' too much.

When I make then macro to my pdf file, I will get the same warning in the log as I describe earlier.

The name will still looks like O'Leary.

 

How can I make the name as O%str(%')Leary ?

Tom
Super User Tom
Super User

@steen_soeskov_sof_kk_dk wrote:

Hi

If I make name in my data step, I will still have a apostrophe ' too much.

When I make then macro to my pdf file, I will get the same warning in the log as I describe earlier.

The name will still looks like O'Leary.

 

How can I make the name as O%str(%')Leary ?


You are missing a step here. How is the data getting out of the dataset variable and into the TITLE statement?  Please show that code for more detailed help.

 

If you have the value in a data step variable and leave it there the quote (or any other character that SAS would consider special in code) is no problem.  Why not generate the macro variable for making the TITLE statement with the quotes already around the value?

So if you have a dataset variable named TITLE and you want to use it as a title then convert it to a quoted string in a macro variable. 

data _null_;
  set titles;
  call symputx('title',quote(trim(title),"'"));
run;
title &title;

If you have the value in a macro variable you can use a macro quoting function.  %SUPERQ() is a good function to use since you don't need to expand the macro variable.  So if you made a macro variable named TITLE and you wanted to use its value as a title you might use this statement.

TITLE "%superq(title)";
steen_soeskov_sof_kk_dk
Calcite | Level 5

Hi

One more try.

 

%macro pdf(name);

options orientation=landscape;

ods noresults;

ods pdf file="c:\School 2019.pdf";

ods escapechar='^';

 

ods pdf text="^S={just=c fontweight=bold font_size=10} School 2019.";

ods pdf text="^S={fontweight=bold font_size=5} Name: &name.";

ods pdf text="^n";

 

PROC REPORT DATA=work.fravaer LS=158 PS=97  SPLIT="/" CENTER missing nowd;

COLUMNS name;

DEFINE name / display 'Elevens navn' style(column header)=[font_weight=bold];

RUN; 

ods pdf close;

%mend pdf;

 

/*Here is a program to make the macro to make the pdf-call %pdf(O'Leary);*/

 

filename bo2 catalog "work.SASCatalog.bo2.source" lrecl=32767 recfm=v;

data _null_;

file bo2;

length cpr codeline $4000. pct_fravaer 8.;

set fravaer_nuv_skoleaar_barn;

by cpr sort_md pct_fravaer;

if last.cpr;

codeline = "%" !! "pdf("!!name!!");";

put codeline;run;

%inc bo2;

 

How do I make the apostrophe be a part of the text in name, and not a part of the SAS code ?

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 6 replies
  • 2561 views
  • 1 like
  • 4 in conversation