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

Hi all, in order to convert a numeric variable to character WITH LENGTH=30 I use the function PUT:

VARC=PUT(VARN,30.);

but my problem appears when I try to convert a variable with length=40, or bigger:

VARC=PUT(VARN,50.);...it gives me an error of width

any help?

Thanks in advance,

V.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Well, this would work:

data want;

set have;

length varc $ 50;

varc = right(put(varn, 15.));

run;

But the answer is that's the way SAS built the w.d format.  Maximum width is 32, per the documentation:

http://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML/default/viewer.htm#n1n7bmvs1brl...

View solution in original post

7 REPLIES 7
Astounding
PROC Star

You have to realize that your data values are probably incorrect.  SAS does not accurately store numbers beyond 15 or 16 significant digits.  Here is a program you can run to illustrate:

data _null_;

x=12345678901234567890;

put x 20.;

run;

With that in mind, is your original question something that you need to solve or do you need to rethink an earlier part of the process?

michtka
Fluorite | Level 6

***It is fine;

data new;
varn=3;
varc=compress(put(varn,30.));
run;

***It is not;


data new2;
varn=3;
varc=compress(put(varn,40.));
run;

ERROR 29-185: Width specified for format F is invalid.

Q is....How can obtain varc with LENGHT = 40 or superior.

I hope it is more clear now, Thanks.

Astounding
PROC Star

OK, this won't solve the problem if it turns out that your data values are already incorrect.  But it will convert them:

data want;

set have;

length varc $ 50;

varc = varn;

varc = left(varc);

run;

You can always omit the LEFT function if you prefer.  But don't combine into one statement.  You'll get scientific notation if you try:  varc = left(varn);

Good luck.

michtka
Fluorite | Level 6

Thanks for that, but still not convince with your answer, sorry, my Q is , why can't do it with the PUT function, this my question Smiley Happy. Thanks.

michtka
Fluorite | Level 6

This is like I want to achieve, as you can see, I need the length superior to 30, because the lenght need to match to add this extraline with PROC APPEND Smiley Happy

data new;
varn=3;
varc=compress(put(varn,30.));
run;


data new2;
varn=3;
varc=compress(put(varn,40.));
run;

data extra; length varc $30.;retain varc "Numbers of subjects living in the island of the Pacific Ocean" varn 0 ;run;  /* 30 is not enoguh */
proc append base=new data=extra;run;

Astounding
PROC Star

Well, this would work:

data want;

set have;

length varc $ 50;

varc = right(put(varn, 15.));

run;

But the answer is that's the way SAS built the w.d format.  Maximum width is 32, per the documentation:

http://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML/default/viewer.htm#n1n7bmvs1brl...

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 15788 views
  • 3 likes
  • 2 in conversation