DATA Step, Macro, Functions and more

Convert a character variable into a numeric variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Convert a character variable into a numeric variable

Hello,

I created two macro variables using proc sql select into. My expectation is that I will get two numbers and then continue to next step. The part of my is below:

proc sql noprint;

  select min(mean),max(mean)

  INTO :mini,

  :maxes

  from plot1;

quit;

%LET low=%eval(&mini-10);

%LET upper=%eval(&maxes+10);

The error messages are:

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric

       operand is required. The condition was: 290.6-10

ERROR: The macro PLOT will stop executing.

I know one way to use input function in data step but not sure how to achieve my goal in this situation.

Any suggestions are welcome and thanks for all.


Accepted Solutions
Solution
‎01-30-2015 12:57 PM
Respected Advisor
Posts: 3,156

Re: Convert a character variable into a numeric variable

%eval is only good for integers. replace it with %sysevalf().

View solution in original post


All Replies
Solution
‎01-30-2015 12:57 PM
Respected Advisor
Posts: 3,156

Re: Convert a character variable into a numeric variable

%eval is only good for integers. replace it with %sysevalf().

Occasional Contributor
Posts: 9

Re: Convert a character variable into a numeric variable

Yes, that's it!

Thank you!

Super User
Posts: 11,343

Re: Convert a character variable into a numeric variable

How about

select (min(mean) -10),(max(mean)+10) into : low , :upper

and avoid the extra step?

Of course if you also need mini and maxes that's not needed.

Occasional Contributor
Posts: 9

Re: Convert a character variable into a numeric variable

That's really a good idea. Though I still need the %sysevalf function to convert it into numeric.

Respected Advisor
Posts: 3,799

Re: Convert a character variable into a numeric variable

Why put the numbers into macro variables at all?  What is your "next step"?

Occasional Contributor
Posts: 9

Re: Convert a character variable into a numeric variable

Posted in reply to data_null__

I need to plot thousands of pics. Those two numbers are the upper and lower bound of axes.

Respected Advisor
Posts: 3,799

Re: Convert a character variable into a numeric variable

For axis scaling I would look at the IML routine GSCALE.  I it takes min and max values and produces nice tick marks using some criteria that you can adjust, like Number of Ticks.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 381 views
  • 3 likes
  • 4 in conversation