BookmarkSubscribeRSS Feed
ncsthbell
Quartz | Level 8

Hello,

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.
5 REPLIES 5
Reeza
Super User

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.

ncsthbell
Quartz | Level 8

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;

input(3903918260,16.)

 

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!!!

 

 

 

Reeza
Super User

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.

 

 

 

 

Astounding
PROC Star

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:

 

data fy&year;

 

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.

moorsd
Obsidian | Level 7

You could try using %SYSFUNC and inputn/putn.

 

See below:

 

%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 ***

 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1243 views
  • 2 likes
  • 4 in conversation