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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2216 views
  • 0 likes
  • 5 in conversation