03-18-2016 12:06 PM
I have several prompts, 'FGR', 'DATA1' & DATA2'. This data is character so I defined the prompt in SMC as character type. However, I need to compare to a numeric value so in my code I am using 'call symput' to convert to a numeric value.
What I am finding in testing is that if I have a value in the prompt, the code works. However, the user may only enter one value and leave the other 2 blank. In my example I have entered a value into 'FGR' but left 'DATA1' & 'DATA2' blank.
Any suggestions would be greatly appreciated.
80 Call symput(('NEW_FGR),(input(&FGR,16.))); 82 Call symput(('NEW_DATA1'),(input(&DATA1,16.))); _ 22 83 Call symput(('NEW_DATA2'),(input(&DATA,16.))); _ 22 ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, INPUT, PUT. a missing value, INPUT, PUT.
03-18-2016 12:10 PM
CALL SYMPUT creates a macro variable that will always be text.
Please post an example of how resolving the macro variable is causing issues and we can make suggestions on how to resolve it.
03-18-2016 12:29 PM
Not sure I understand what you want me to post. I posted the source code that I am using to convert the character to numeric value. Since you mentioned that 'call symput' returns a text value then I do not need to use it, I want numeric returned.
I tried another way to assign the converted character to numeric value to a variable by doing this:
%let NEW_FGR = input(&FGR,16.);
I used a put statement to display 'NEW_FGR' and this is what was returned:
116 %put &NEW_FGR_FROM_AMT;
It appears that it did not apply the 'input' to convert from char to numeric but rather used the whole string as the new value for 'NEW_FGR'. This seems like it be easy to do just to convert to numeric and assign to a variable but I just can't seem to get it right! I have spent several hours on this!!!
03-18-2016 12:58 PM
Where are you trying to use those macro variables?
Creating new macro variables will not change the type, it changes the appearance.
All macro variables are text - how you use them is what matters.
03-18-2016 01:05 PM
Reeza has hit on the right issue here. Your macro variables are fine. It's how you use them later that matters. To give you an example:
%let year = 2016;
&YEAR is always the set of characters: 2016
SAS will see how you use &YEAR, and make a determination as to whether they are text of a number. For example:
SAS decides that 2016 is text, and "fy2016" is the name of the data set to create.
next_year = &year + 1;
SAS decides that 2016 is numeric, ans uses it to perform math.
In both cases, SAS is deciding whether to treat the characters as text or as numeric. Macro langauge is not deciding.
03-18-2016 01:10 PM
You could try using %SYSFUNC and inputn/putn.
%let FGR = 3903918260;
%let NEW_FGR = %sysfunc(putn(&FGR,comma16.));
%put NEW_FGR is: *** &NEW_FGR ***;
Output the following to the Log:
NEW_FGR is: *** 3,903,918,260 ***