DATA Step, Macro, Functions and more

Resolving a macro variable of having length 65k

Reply
Contributor
Posts: 33

Resolving a macro variable of having length 65k

 

Proc sql;

select data into  :data_macro seperated by "," from xyz;

quit;

 

Lets assume data_macro recorded a string of 65k length.

 

Now :

 

data test;

data_list="&data_macro"; /*Here error comes of truncation*/ 

run;

 

Since character varibale can store max 32767 byte of data i am wondering how will i able to store this macro value into my dataset.

 

Kindly suggest.

 

Thanks

Super User
Posts: 10,530

Re: Resolving a macro variable of having length 65k

Posted in reply to Attyslogin

Since the data is originally stored in a column over all (or multiple) rows, I'd keep it that way and use it from there. Adapt your process to the structure.

 

With an arbitrary number of rows, sooner or later you'll crack the 65k limit of the macro variable and lose data there. So your process as such is not valid.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Respected Advisor
Posts: 3,251

Re: Resolving a macro variable of having length 65k

Posted in reply to Attyslogin

data test;

data_list="&data_macro"; /*Here error comes of truncation*/ 

run;

 

I can't imagine a reason to do this, why you'd want to create a data step variable that long from a macro variable, what is the point?

 

But when you start dealing with large amounts of text like this, the idea of making a huge long text string or huge long macro variable is not a good one. Using a function like CALL EXECUTE, you can actually work with arbitrarily large amounts of text, if you do it properly.

 

 

--
Paige Miller
Super User
Super User
Posts: 8,264

Re: Resolving a macro variable of having length 65k

Posted in reply to Attyslogin

There is a simple answer DON'T.

 

If you describe the larger problem I am sure there is a way to solve it without creating strings anywhere near the 32K limit for a variable to or the 64K limit for a macro variable.

 

If you really want to generate really long strings from your data then just do that and skip the macro variable step.

data test ;
  length row 8 data_list $500 ;
  do row=1 by 1 until (eof or length(data_list) > 450) ;
    set xyz end=eof ;
    data_list = catx(',',data_list,data);
  end;
  keep row data_list ;
run;
PROC Star
Posts: 618

Re: Resolving a macro variable of having length 65k

Posted in reply to Attyslogin

Instead of saving it into a single macro, you can use CALL SYMPUT in data step and create multiple macro variables depending on the condition you have and later you can call them as needed. 

 

Thanks,
Suryakiran
Super User
Posts: 13,889

Re: Resolving a macro variable of having length 65k

Posted in reply to Attyslogin

@Attyslogin wrote:

 

Proc sql;

select data into  :data_macro seperated by "," from xyz;

quit;

 

Lets assume data_macro recorded a string of 65k length.

 

Now :

 

data test;

data_list="&data_macro"; /*Here error comes of truncation*/ 

run;

 

Since character varibale can store max 32767 byte of data i am wondering how will i able to store this macro value into my dataset.

 

Kindly suggest.

 

Thanks


And just what were you going to do with the data step variable data_list?

Sticking that many data values into macro variables is almost always an indication of attempting to do something in the macro facility it was not designed for. Not to mention what is going to be done with one variable roughly the equivalent of 300 pages of text...

Super User
Posts: 23,958

Re: Resolving a macro variable of having length 65k

Posted in reply to Attyslogin

See the recommendation here:

http://support.sas.com/kb/39/605.html

 

Check the full code tab for the code.

Ask a Question
Discussion stats
  • 6 replies
  • 120 views
  • 0 likes
  • 7 in conversation