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

I have this below macro that runs fine for when xrow=1 to 99, but as soon as I put in anything over 100 it keeps generating this error that I don't understand.

 

ERROR: Invalid value for width specified - width out of range
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.


I looked up some helpful articles that say it may be a format issue, but I am not sure what format I would need to allow it to read > 100 and all the ones I have tried have not worked. Any help is much appreciated!! Thank you!

 

%Macro MYC(xdata,xrow);
proc sql noprint;
select filter,biomarks, group, exclude, number, title,
strip("TAB"||strip(put(ID,z2.))||"A") as tab, strip("Table "||strip(number)||": "||strip(title)) as ftabtitle,
strip(tranwrd(title,'Endpoints – ',' ')) as stabtitle
into: xfilters, :xbiomark, :xgroup,  :xexclude, :xtabnum, :xtabtitle, :xtab, :xftabtitle, :xstabtitle
from input.data
where ID = &xrow;
quit;

%mend MYC;

%MYC(input.data_new,100);

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Buried in your select statement is the expression:

put(ID,z2.)

which precedes the clause

where ID = &xrow;

So your macro call

%MYC(input.data_new,100);

means that the put(ID,z2.) will attempt to write the value 100 in a 2-digit character space.   Change the z2. to a format that can accommodate the 3-digit value of 100.

 

--------------------------
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

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

Buried in your select statement is the expression:

put(ID,z2.)

which precedes the clause

where ID = &xrow;

So your macro call

%MYC(input.data_new,100);

means that the put(ID,z2.) will attempt to write the value 100 in a 2-digit character space.   Change the z2. to a format that can accommodate the 3-digit value of 100.

 

--------------------------
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

--------------------------
kmardinian
Quartz | Level 8

Thank you so much, I definitely missed that! Works perfectly now!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 4472 views
  • 0 likes
  • 2 in conversation