## Length of macro variable

Solved
Super Contributor
Posts: 712

# Length of macro variable

proc sql;

select distinct "'"||compress(networkid)||"'"

into :nwid SEPaRATED BY ","

from a1.nw_master

where srv>0;

where id in (&&nwid.);

ERROR: The length of the value of the macro variable NWID (987973) exceeds the maximum length (65534). The value has been truncated

to 65534 characters.

I thought all distinct values will be selected into nwid macro.

Accepted Solutions
Solution
‎01-29-2013 02:19 PM
Posts: 3,852

## Re: Length of macro variable

This example is contrived but shows what you "could" do.

proc sql;

select * from sashelp.class

where name in(select name from sashelp.class where sex eq 'M');
quit;

run;

All Replies
Super Contributor
Posts: 578

## Re: Length of macro variable

I'm not sure you need the double ampersand.

Solution
‎01-29-2013 02:19 PM
Posts: 3,852

## Re: Length of macro variable

This example is contrived but shows what you "could" do.

proc sql;

select * from sashelp.class

where name in(select name from sashelp.class where sex eq 'M');
quit;

run;
Super User
Posts: 23,664

## Re: Length of macro variable

All distinct values will be selected but your string must be longer than the 65k character length.

You can check if that is the case by calculating the number of distinct network ID and then multiplying by 3+ length of network id: total length ~ # of distinct * (length of networkID + 3).

If thats close to 65K then you have a problem.

Super Contributor
Posts: 712

## Re: Length of macro variable

Ok..If it greater than 65K sas cannot handle isnt it

Posts: 3,852

## Re: Length of macro variable

You don't need the macro variable.

Super User
Posts: 23,664

## Re: Length of macro variable

You can use a subquery as shown by Data _null_ or create a macro like identified in this link:

39605 - Create a string that goes beyond the 64K limit for macro variables

I'd go with a subquery, since both tables seem to be in the same location and it would be the fastest.

🔒 This topic is solved and locked.