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

I have a macro variable which I first need to convert it to a number and do some mathematical calculation, then I have to cover it with a single quote and bracket.

 

%let num1= 1000;
%let num2= 1000 - 100;
%let output = ('&num1.','&num2.');

 

I need output like this:

('1000','900')

 

1 ACCEPTED SOLUTION

Accepted Solutions
bhu
Obsidian | Level 7 bhu
Obsidian | Level 7

I found the solution:

%let num1 = '1000';
%let num2 = %sysevalf(%sysfunc(compress(&num1.,"'"))-10);
%let output = (&num1.,%tslit(&num2.));
%put &num1.;
%put &num2.;
%put &output.;

View solution in original post

4 REPLIES 4
bhu
Obsidian | Level 7 bhu
Obsidian | Level 7

I found the solution:

%let num1 = '1000';
%let num2 = %sysevalf(%sysfunc(compress(&num1.,"'"))-10);
%let output = (&num1.,%tslit(&num2.));
%put &num1.;
%put &num2.;
%put &output.;

Ksharp
Super User

 

 

%let num1= 1000;
%let num2= 1000 - 100;
%let output = (%bquote('&num1.','%eval(&num2.)'));

%put &output ;


novinosrin
Tourmaline | Level 20

Hey  Xia  @Ksharp 

 

I know too well that you are intelligent. But unfortunately i am not,so

 

Can you please give me a hand to help my understanding if you have a couple of mins

 

Does the %bquote here force macro resolution  inside '&var' and then quote the value? Is this behavior consistent?

 

I am keen to understand how the macro processor works here. 

 

 

Sorry for the bother if you are busy

 

 

Ksharp
Super User

Hi. Thanks everything you do for sas communitity.

 

"Does the %bquote here force macro resolution  inside '&var' and then quote the value? Is this behavior consistent?"

Answer is no. As far as I know %bquote firstly mask single quote , since quote has been masked ,then resolving  macro variable & var is nature thing ,as %let x=&var ;  .did .

Hope this could give you some hint .

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
  • 2928 views
  • 3 likes
  • 3 in conversation