DATA Step, Macro, Functions and more

Macro quoting problem

Reply
N/A
Posts: 0

Macro quoting problem

I have what I think is a quoting problem. In the code below the PUT/SELECT statement doesn't work because the macro variables are inside single quotes. Is there a way around this?


filename cmds dde "excel|system";
data file3x_reformat;
file cmds;
%macro reformat;
%do i=1 %to &count_header;
%let selectcmd =
put '[select("R&&Header&I..C1:R&&Header&I..C1")]';
put '[font.properties("MS Sans Serif","Bold",10,,,,,,,1)]';
%end;
%mend reformat;
%reformat;
run;
Frequent Contributor
Posts: 102

Re: Macro quoting problem

I've had luck putting a single quote in a marco var and using it instead of quotes in the put statements. Something like this (untested because I don't have your data).

%let q = %nrstr(%');
%put &q;

filename cmds dde "excel|system";
data file3x_reformat;
file cmds;
%macro reformat;
%do i=1 %to &count_header;
%let selectcmd =
put &q.[select("R&&Header&I..C1:R&&Header&I..C1")]&q.;
put &q.[font.properties("MS Sans Serif","Bold",10,,,,,,,1)]&q.;
%end;
%mend reformat;
%reformat;
run;

Curtis
N/A
Posts: 0

Re: Macro quoting problem

Curtis,

Thanks for your reply. When I run your code I get the following errors:



371 put &q.[select("R&&Header&I..C1:R&&Header&I..C1")]&q.; put
______
68
371 ! '[font.properties("MS Sans Serif","Bold",10,,,,,,,1)]';
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, arrayname,
#, (, +, /, //, ;, @, @@, OVERPRINT, _ALL_, _BLANKPAGE_, _ODS_, _PAGE_.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 68-185: The function SELECT is unknown, or cannot be accessed.

ERROR: Undeclared array referenced: NAME.

_
22
200
Frequent Contributor
Posts: 102

Re: Macro quoting problem

I suspected that would happen, but I did not know what the rest of the code would do.

I think what you might really want to do is use double quotes and then double them up when you want one inside the string.

data file3x_reformat;
file cmds;
%macro reformat;
%do i=1 %to &count_header;
%let selectcmd =
put "[select(""R&&Header&I..C1:R&&Header&I..C1"")]";
put "[font.properties(""MS Sans Serif"",""Bold"",10,,,,,,,1)]";
%end;
%mend reformat;
%reformat;
run;

This assumes that your code has a pseudo macro array of HEADER1 - HEADER&count_header;
N/A
Posts: 0

Re: Macro quoting problem

Thanks Curtis, that worked!

Jeff
Ask a Question
Discussion stats
  • 4 replies
  • 371 views
  • 0 likes
  • 2 in conversation