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!

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!

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
  • 2 replies
  • 3628 views
  • 0 likes
  • 2 in conversation