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.
 


 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 648 views
  • 0 likes
  • 3 in conversation