BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AlexeyS
Pyrite | Level 9

Hello guys, I want to use macro variables inside the put statement. When I use numbers it works perfectly, but when I replace numbers with macro variables, it doesn't work.

 

filename DDEcmds  dde 'excel|system';

 

data _null_;
file DDEcmds;
put '[select("R2C%sysevalf(&id+3):R100C%sysevalf(&id+3)")]';
put '[Format.Number("#,##0")]';    
run;

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @AlexeyS,

 

You can use double quotes and double double quotes to avoid the single quotes:

 

put "[select(""R2C%sysevalf(&id+3):R100C%sysevalf(&id+3)"")]";

 

View solution in original post

4 REPLIES 4
DanielLangley
Quartz | Level 8

Macro Variables don't resolve if they are within single quotes.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You are not resolving the macro code.  To resolve macro code it needs to be within double quotes:

'[select("R2C%sysevalf(&id+3):R100C%sysevalf(&id+3)")]';

The double quotes here are within single quotes, therefore part of the text.  Maybe something like.

data _null_;
  file DDEcmds;
  str=cats('[select(',"R2C%sysevalf(&id+3):R100C%sysevalf(&id+3)"),']');
  put str;
  put '[Format.Number("#,##0")]';    
run;

Again though, DDE is a dead technology, from 30 years + out of service.

FreelanceReinh
Jade | Level 19

Hello @AlexeyS,

 

You can use double quotes and double double quotes to avoid the single quotes:

 

put "[select(""R2C%sysevalf(&id+3):R100C%sysevalf(&id+3)"")]";

 

Kurt_Bremser
Super User
put '[select("R2C%sysevalf(&id+3):R100C%sysevalf(&id+3)")]';

The outermost single quotes prevent all macro trigger resolution.

Use an intermediate string:

length string $50;
string = '[select("R2C' !! "%sysevalf(&id+3):R100C%sysevalf(&id+3)" !! '")]';
put string;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 4 replies
  • 2378 views
  • 0 likes
  • 5 in conversation