BookmarkSubscribeRSS Feed
gstover
Fluorite | Level 6

I am trying to create a retain variables in a statement that is over 6000 characters long and getting an error - please help!

10 REPLIES 10
PaigeMiller
Diamond | Level 26

What error are you getting? Show us the ENTIRE log for the data step in which you are using RETAIN — do not show us a partial log. Copy the log as text, paste it into the window that appears when you click on the </> icon.

Insert Log Icon in SAS Communities.png

--
Paige Miller
gstover
Fluorite | Level 6

There is no log.  Trying to order the variables on the output and there are 998 variables.

 

gstover_0-1689016485367.png

 

 

PaigeMiller
Diamond | Level 26

What happens if you split this long list of variables across many lines?

--
Paige Miller
ballardw
Super User

That error message refers to length of a single line of code. Can't exceed 6000 characters. So your Subject line is incorrect.

Use multiple Length statements. They will be processed in order of appearance in the code so

Length var1 var2 var3 8 ;
Length var15 var16 var17 $ 5;

is equivalent to

Length var1 var2 var3 8 var15 var16 var17 $ 5;

 

But I still don't see why so many people spend so much time worrying about the order of variables in a data set...

PaigeMiller
Diamond | Level 26

@ballardw wrote:

 

But I still don't see why so many people spend so much time worrying about the order of variables in a data set...


I think it is unnecessary and a waste of effort as well, but its a rare event when I can convince someone who is determined to order the variables in a data set to NOT do that.

--
Paige Miller
gstover
Fluorite | Level 6

The reason for the order is because it is for a data submission that has this requirement.

The variables are in the dataset and need to be put out to a file in this order.  Can I use a length statement even with the variables already created?

 

mkeintz
PROC Star

@ballardw wrote:

But I still don't see why so many people spend so much time worrying about the order of variables in a data set...


I do.  Because

  1.  I often benefit from using the double dash technique for referring to a related group of variables in a list, mostly for arrays or keep/drop lists.

  2. Probably even more often, I want to see the related variables together in a data window, and don't want to bother making any extra effort to make them appear contiguous.

Yes, it's possible to overstress variable order, but it's not a worthless objective.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

No need to make separate statements.  Just make separate lines.

 

PS: I don't understand why people spend so much time making datasets with variables in some random order (or some even worse order) that makes it almost impossible to look at the data.  It takes almost no effort to define the variables in a rational order.

mkeintz
PROC Star

So your SAS installation doesn't want statements longer than 6000 characters, and you apparently have some statement (maybe a LENGTH statement since that's what shows in your popup window) longer than 6000 characters.

 

So make multiple LENGTH statements, each no more than 6000 characters.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

The message is not about the length of a VARIABLE or even the length of the value of a variable.

It is about the length of line in the file that has the code.

So when you write the code to the file split the long lines into multiple lines.  SAS does not care how long the STATEMENT is, but it obviously cannot reads lines of code that have over 6000 characters (at least using whatever method you used to submit the code).

But in practical terms you should not be making lines of code that is longer than about 70 to 75 characters anyway so that HUMANS can read them.

 

Also your code is using a LENGTH statement, not a RETAIN statement.  If the purpose of the RETAIN statement was just to force the ORDER then it must come BEFORE the variables are defined by a LENGTH or a SET or any other statement that would set the order, type and length of the variable.

 

How did you create that giant LENGTH statement?

 

If you created from a source dataset then just limit the length of the lines while writing the statement.

 

So for example if you have a dataset named HAVE and a metadata dataset named VARIABLES you can use the two of them to create a dataset named WANT that has the variables in the order they appear in VARIABLES with code like this:

filename code temp;
data _null_;
   set variables  end=eof;
   file code lrecl=75 ;
   if _n_=1 then put 'RETAIN ' @;
  put name @ ;
  if eof then put / ';' ;
run;

data want;
%include code / source2;
  set have;
run;
   

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 918 views
  • 2 likes
  • 5 in conversation