DATA Step, Macro, Functions and more

macros

Reply
Contributor
Posts: 28

macros

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.

Super User
Posts: 23,776

Re: macros

Posted in reply to VISHNU239
%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.
User
Posts: 1

Re: macros

Posted in reply to VISHNU239

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)Smiley SadColumn).
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.
 

Super User
Posts: 23,776

Re: macros

Posted in reply to afafsafawa

@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)Smiley SadColumn).
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.
 


 

Ask a Question
Discussion stats
  • 3 replies
  • 35 views
  • 0 likes
  • 3 in conversation