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.
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:
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?
***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.
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.
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 . Thanks.
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
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;
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:
Thanks
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.
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.