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

Hi,

 

I am having trouble labeling all of a certain type of variable with the same label.

 

The code that I have is the following:

 

%macro Label(Exp);
data sub.master_dataset053019;
set sub.master_dataset053019;

%do i=1 %to %sysfunc(countw(&exp));
    %let thisexp=%scan(&exp,&i,%str( ));
	label I_PostResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1st6mo_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1st6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	%end ;
run;
%mend;

%label(house consume durable Trans health Insure Loan Tax Educa Gift Enter REcre FinPlan Legala AlcSpend ST2DENOM2 ST2DENOM3 ExpendTl FinPlSav IncomeTL ST2Oblig);

I an receiving 1787 errors indicating that my text is too long, but it doesnt seem to pass the 256 characters in the label?

 

Error:

1          ;*';*";*/;quit;run;
ERROR: The text expression length (65580) exceeds maximum length (65534). The text expression has been truncated to 65534 
       characters.

I am at a loss. Could I be using the macro inappropriately? I have used almost the same macro more than once and it worked flawlessly.

 

Any help would be appreciated.

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If this is supposed to be a block of label instructions:

	label I_PostResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1st6mo_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1st6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";

You have too many semi colons.

Try

	label 
      I_PostResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr1st6mo_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr1st6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   ;

Other than the first line with the actual LABEL statement SAS thought you were attempting to assign the string as the value of the variable, NOT a label.

 

BTW you don't need the %str() in this:

%let thisexp=%scan(&exp,&i,%str( ));

as a blank is a default parameter for %scan. Use

%let thisexp=%scan(&exp, &I );

 

The error of exceeding character length probably means you have gotten into an unstable state, probably due to a mismatched quote or () somewhere. Save the code and restart SAS.

View solution in original post

5 REPLIES 5
ballardw
Super User

If this is supposed to be a block of label instructions:

	label I_PostResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1st6mo_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1st6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PreResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";
	I_PostResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs";

You have too many semi colons.

Try

	label 
      I_PostResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr1st6mo_&thisExp = "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr1st6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr2nd6mo_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr1stQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr2ndQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr3rdQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr4thQ_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr1stT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr2ndT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PreResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   	I_PostResYr3rdT_&thisExp= "+1 to all I_ Variables for 0's in prop/Logs"
   ;

Other than the first line with the actual LABEL statement SAS thought you were attempting to assign the string as the value of the variable, NOT a label.

 

BTW you don't need the %str() in this:

%let thisexp=%scan(&exp,&i,%str( ));

as a blank is a default parameter for %scan. Use

%let thisexp=%scan(&exp, &I );

 

The error of exceeding character length probably means you have gotten into an unstable state, probably due to a mismatched quote or () somewhere. Save the code and restart SAS.

joebacon
Pyrite | Level 9

@ballardw As always, you are a wizard. I had tried an iteration without all the semi-colons and assumed I was incorrect.

 

Saving and restarting did the trick. Thank you!

 

Also, good to note about blank being the default parameter for scan. I appreciate you taking your time to help me!

FreelanceReinh
Jade | Level 19

Hi @joebacon,

 

If the macro adds or modifies variable labels, but doesn't change variable values (or the structure of the dataset), there is no need to read and write the whole (possibly huge) dataset using a DATA step. PROC DATASETS could do this much more efficiently:

proc datasets lib=sub nolist;
modify master_dataset053019;
label ...
      ...
;
quit;

For the LABEL statement use the same syntax as you did in the DATA step (after the correction). Also the macro logic remains unchanged.

joebacon
Pyrite | Level 9

Man, I have been on many forums and this one is the only one that the individuals truly go out of their way to help you.

 

Thank you so much! Computationally, that is way faster. A great suggestion that I would have never even attempted.

ballardw
Super User

@joebacon wrote:

Man, I have been on many forums and this one is the only one that the individuals truly go out of their way to help you.

 

Thank you so much! Computationally, that is way faster. A great suggestion that I would have never even attempted.


A data step always loads all of the records into the data vector and then writes them to the output data set and that can take time that is noticeable when the data set is even only moderate in size.

The Proc Datasets is writing to the header information of the file so even when a data set is many times larger the time involved is almost the same,

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1102 views
  • 6 likes
  • 3 in conversation