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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 7 replies
  • 14052 views
  • 3 likes
  • 2 in conversation