Solved
Contributor
Posts: 58

# SELECT INTO numeric macro variable

Hello!

I am trying to create a marco variable x, that countains numbers. However there are always leading blanks. As i want to use the macro variable later in a table name, it must not contain blanks. I found a solution to this Problem using %sysfunc. However, I am wondering: Is there an "easier" war to do that?

Thank you,

S.

---------------------------------------------------------

/* kleinste Primzahl bestimmen */

title 'Primzahl';

proc sql;

select min(primzahl) INTO x

from temp;

/* Primzahl aus der Liste entfernen */

delete from temp

where primzahl=&x;

quit;

/* kleinste Primzahl formatieren */

%LET X = %sysfunc(cat(&x));

%put Primzahl = &x;

/* Quadrate mod x bestimmen */

data tempi;

do Basis = 1 to &x;

Quadrat_mod_&x = mod(Basis ** 2, &x);

output;

end;

run;

Accepted Solutions
Solution
‎05-14-2012 08:20 AM
Regular Contributor
Posts: 151

## Re: SELECT INTO numeric macro variable

One way is simply to add the CAT function to the SQL statement

select cat(min(primzahl))

All Replies
Solution
‎05-14-2012 08:20 AM
Regular Contributor
Posts: 151

## Re: SELECT INTO numeric macro variable

One way is simply to add the CAT function to the SQL statement

select cat(min(primzahl))

Posts: 3,167

## Re: SELECT INTO numeric macro variable

Thanks, Keith. That is a really neat way to use cat() or cats().

If going for the 'more' text-book style approach, OP can also try:

select left(put(min(primzahl),8.))

Regards,

Haikuo

Contributor
Posts: 58

## Re: SELECT INTO numeric macro variable

Hello Hai.kou,

thank you very much for your help! is there any advantage to your code except for its textbookness? ;-)

Regards, Stefan

Posts: 3,167

## Re: SELECT INTO numeric macro variable

I doubt that, as my approach involves one more function than Keith's. That being said, if you want to know the truth difference in term of efficiency, you probably need to benchmark it.

Regards,

Haikuo

Contributor
Posts: 58

## Re: SELECT INTO numeric macro variable

Thank you, Keith! it works :-)

Super User
Posts: 10,784

## Re: SELECT INTO numeric macro variable

select put(min(primzahl),32.-L))

or

%LET X = %left(&x);

Super Contributor
Posts: 398

## Re: SELECT INTO numeric macro variable

A "trick" I learned a while back (via SAS-L) is to use "separated by".  For a single numeric return value, it will strip leading and trailing blanks.

data one;

x=1;

run;

proc sql noprint;

select x into :mvar separated by " " from one;

quit;

%put *&mvar*;

HTH,

Scott

🔒 This topic is solved and locked.