BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PeterClemmensen
Tourmaline | Level 20

Hi all.

 

Can someone help me understand and resolve this problem?

 

data have;
   do x = 1 to 10000;
      output;
   end;
run;

proc sql noprint;
   select x into :x1 -
   from have;
   %let t = &sqlobs.;
quit;

%put &x1.;
%put &x10000.;

%macro m;
   %do i=1 %to &t.;
      &&x&i
   %end;
%mend;

%put %m;

This gives me quite a lot of the error message below.

 

"ERROR: The text expression length (65545) exceeds maximum length (65534). The text expression has
been truncated to 65534 characters."

 

Why does this happen? Works fine with less macro variables?

 

This is purely for my own understanding, I am well aware that one should not create this many macro variables (as I'm sure @Kurt_Bremser will remind me 🙂 )

 

Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

It is not a problem of the macro, it is a problem of %PUT:

data have;
   do x = 1 to 10000;
      output;
   end;
run;

proc sql noprint;
   select x into :x1 -
   from have;
   %let t = &sqlobs.;
quit;

%put &x1.;
%put &x10000.;

%macro m;
   %do i=1 %to &t.;
      x&&x&i. = 0;
   %end;
%mend;

data test;
%m
run;

Runs without problems and creates a dataset with 10000 variables.

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

It's a function style macro, it returns a string that is too long ...

--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Ok, so this is not because the individual macro variables are two long?

 

How would I resolve this problem?

Kurt_Bremser
Super User

It is not a problem of the macro, it is a problem of %PUT:

data have;
   do x = 1 to 10000;
      output;
   end;
run;

proc sql noprint;
   select x into :x1 -
   from have;
   %let t = &sqlobs.;
quit;

%put &x1.;
%put &x10000.;

%macro m;
   %do i=1 %to &t.;
      x&&x&i. = 0;
   %end;
%mend;

data test;
%m
run;

Runs without problems and creates a dataset with 10000 variables.

PaigeMiller
Diamond | Level 26

@PeterClemmensen wrote:

Ok, so this is not because the individual macro variables are two long?

 

How would I resolve this problem?


What resolution do you want?

--
Paige Miller
gamotte
Rhodochrosite | Level 12

Hello,

 

The %put instruction will not accept a string that is more than 65534 characters long

whether is is generated by a macro, macrovariables or typed on the keyboard.

If by "resolving the problem" you mean displaying a longer string in the log you can

use the '@' character in a data step put statements :

data _NULL_;
do i=1 to 70000;
put '1'@;
end;
run;
Astounding
PROC Star

The problem originates within PROC SQL.  It is creating individual macro variables that are longer than you expect.  You can easily see this by running:

%put *&x1*;

Since macro variables contain text strings, and all the X values are numeric, this statement forces SQL to perform numeric to character conversions:

   select x into :x1 -
   from have;

Unlike a DATA step, SQL doesn't issue a note in the log about the conversions.  To alleviate the problem, you can try:

   select strip(put(x,best8.)) into :x1 -
   from have;

Of course the size limit for macro variables still exists.  But you don't have to be hitting it with only 10000 integers.

Tom
Super User Tom
Super User

If you use the :var1- syntax to generate multiple macro variables the values are automatically trimmed.

To impact the format used to convert a number into the string stored in the macro variable you can just change the format attached to the variable.

proc sql noprint;
select name,age format=z5. into :n1-,:a1- from sashelp.class;
quit;
%put |&n1|&a1| ;
%put |&n2|&a2| ;
742   %put |&n1|&a1| ;
|Alfred|00014|
743   %put |&n2|&a2| ;
|Alice|00013|

 

FreelanceReinh
Jade | Level 19

Hi  @PeterClemmensen,

 

You can save a lot of white space by omitting what was likely meant as "code indentation":

%macro m;
   %do i=1 %to &t.;
&&x&i
   %end;
%mend;

The values are now separated by single blanks (rather than seven blanks) in %m, which gets you far below the 65534-character limit and thus avoids the error messages.

129  %put %length(%m);
48893
PeterClemmensen
Tourmaline | Level 20

Thank you all 🙂 Makes more sense now

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Autotuning Deep Learning Models Using SAS

Follow along as SAS’ Robert Blanchard explains three aspects of autotuning in a deep learning context: globalized search, localized search and an in parallel method using SAS.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 9 replies
  • 2413 views
  • 13 likes
  • 7 in conversation