DATA Step, Macro, Functions and more

Convert macro variable to numeric

Reply
Contributor
Posts: 27

Convert macro variable to numeric

[ Edited ]

This may be simple or may not be simple .

 

%let ID=1000 ; 

 

PROC SQL;

SELECT * FROM  TABLE WHERE FORMULARY_ID = INPUT(&ID. ,8.);

QUIT;

 

the conversion is not working. 

 

in the TABLE  the FORMULARY_ID is a Number  , how can i  convert Macro variable to number ?

 

any help would be highly appreciated.

 

Thanks,

M

Contributor
Posts: 25

Re: Convert macro variable to numeric

Posted in reply to mgorripati

The INPUT function is expecting a string. So, try this:

 

%let ID=1000 ; 
 
PROC SQL;
SELECT * FROM  TABLE WHERE FORMULARY_ID = INPUT("&ID". ,8.);
QUIT;

Of course, you don't need to do that. This should work as well.

%let ID=1000 ; 
 
PROC SQL;
SELECT * FROM  TABLE WHERE FORMULARY_ID = &ID.;
QUIT;

HTH

Contributor
Posts: 27

Re: Convert macro variable to numeric

Thanks HTH,

 

INPUT("&ID".,8.) has worked.

 

Super User
Posts: 5,500

Re: Convert macro variable to numeric

Posted in reply to mgorripati

When a macro variable gets passed to a SAS program, it is up to the SAS program to determine whether the value is character or numeric.  You could simply use:

 

where formulary_id=&id.;

Ask a Question
Discussion stats
  • 3 replies
  • 351 views
  • 1 like
  • 3 in conversation