BookmarkSubscribeRSS Feed
VISHNU239
Obsidian | Level 7

Hi I have three macros &a , &b and &c

 

&a  and &b are character and &c is numeric.

I have to convert both &a and &b to numeric and multiply  &b with &c.

&a I am going to use it for further calculations.

 

all three macro variables include decimal values. Please help me.

3 REPLIES 3
Reeza
Super User
%SYSEVALF(). Macro variables are text, not numeric/character. Please show a detailed example of what you’re looking for and why the approach suggested previously did not work.
afafsafawa
Calcite | Level 5

Hello VISHNU239

 

You should be okay to multiply the character variable with the numeric variable. SAS will automatically convert the character values into numeric then perform the operation. SAS will post a NOTE in the log to indicate the conversion.

 

see example below:

 

%let f = '125';
%let g = '12.52';
%let h = 60;

 

data test;
input a $ b $ c;
cards;
12 12.52 60
run;

 

data test2;
set test;
d= &f * &h;
run;

 

NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
1:1
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST2 has 1 observations and 4 variables.
 

Reeza
Super User

@afafsafawa in general that wouldn't be considered a good approach, mostly because if you have errors later on that are the same as this warning it will not be detected. Additionally, this will put you in the habit of ignoring warnings/notes, but they can be really important. A clean log is a very good idea. 

That being said, for quick and dirty calculations or time constraints, I've done this as well. 

 


@afafsafawa wrote:

Hello VISHNU239

 

You should be okay to multiply the character variable with the numeric variable. SAS will automatically convert the character values into numeric then perform the operation. SAS will post a NOTE in the log to indicate the conversion.

 

see example below:

 

%let f = '125';
%let g = '12.52';
%let h = 60;

 

data test;
input a $ b $ c;
cards;
12 12.52 60
run;

 

data test2;
set test;
d= &f * &h;
run;

 

NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
1:1
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TEST2 has 1 observations and 4 variables.
 


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1151 views
  • 0 likes
  • 3 in conversation