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.
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.
@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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.