Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

SAS let statement defines the variable as character or numeric

Reply
Frequent Contributor
Posts: 82

SAS let statement defines the variable as character or numeric

When I write:

%let x = 0.32;

How can I make sure that x is initialized as a numeric variable and not a character variable? I want to be able to do numerical operations on x.

Trusted Advisor
Posts: 3,212

Re: SAS let statement defines the variable as character or numeric

Posted in reply to eagles_dare13

macro variables are always text based as the goal is modify the sas source code.

In normal situations numerical calculations are exceptional in a sas macro as they are processed within a sas-datastep.

Are you sure you are not mixing up some goals of the several different coding languages within a SAS environment?     

---->-- ja karman --<-----
Super User
Posts: 11,343

Re: SAS let statement defines the variable as character or numeric

Posted in reply to eagles_dare13

You can perform numerical calcuations to create additional MACRO variable values using the %sysfunc or %eval<integers only> or %sysevalf.

 

%let x = 0.32;

%let y = %sysevalf(&x * 6.2);

%let z = %sysfunc( max(&x,&y,23));

%put y= &y z= &z;

If the idea is to do numeric operations in a data step then your X variable would be treated and used as a constant value.

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