Hi All,
I'm working on a requirement amount field to text conversion.
My input field Transaction_Amount contains the value £33.17.
I have to output the above value to Thirty three pounds and seventeen cents.
Note - Output should be printed to text with the corresponding any input amount value.
Could you please someone suggest any format or any other technique to accomplish this ?
Thanks in advance for the help.
Anotehr good reason for posting test data in the form of a datastep on every question. Avoids the guessing game. There are formats:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201455.htm
For instance, me, never had to do it, but I would split up the number into two parts, put them into words per the above, then cat the pounds and pence words with that, something like:
data want; set have; pounds=input(scan(put(num,best.),1,"."),best.); pence=input(scan(put(num.,best.),2,"."),best.); want=cat(strip(put(pounds,words10.))," pounds and ",strip(put(pence,words10.))," pence"); run;
Note I cannot test things so you may need to fiddle with it and could be less verbose.
I assume you meant to put a number into pounds format? There is this post:
So the format: nlmnlgbp
From:
http://support.sas.com/documentation/cdl/en/nlsref/61893/HTML/default/viewer.htm#a003090847.htm
Hi,
I'm not trying number into pounds format.
I need to convert pounds into words.
Example :-
Input Output
£33.17 – Thirty three pounds and seventeen cents.
£22.17 - Twenty two pounds and seventeen cents.
Anotehr good reason for posting test data in the form of a datastep on every question. Avoids the guessing game. There are formats:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201455.htm
For instance, me, never had to do it, but I would split up the number into two parts, put them into words per the above, then cat the pounds and pence words with that, something like:
data want; set have; pounds=input(scan(put(num,best.),1,"."),best.); pence=input(scan(put(num.,best.),2,"."),best.); want=cat(strip(put(pounds,words10.))," pounds and ",strip(put(pence,words10.))," pence"); run;
Note I cannot test things so you may need to fiddle with it and could be less verbose.
Just to be clear, is Amount a numeric variable?
Edited @RW9s solution a bit, though all credit goes to him.
data have;
num=33.17;output;
num=22.17;output;
run;
data want(drop=pounds pence);
set have;
pounds=input(scan(put(num,best.),1,"."),best.);
pence=input(scan(put(num,best.),2,"."),best.);
want=cat(strip(put(pounds,words23.))," pounds and ",strip(put(pence,words10.))," pence");
run;
@PeterClemmensen wrote:
Edited @RW9s solution a bit, though all credit goes to him.
data have; num=33.17;output; num=22.17;output; run; data want(drop=pounds pence); set have; pounds=input(scan(put(num,best.),1,"."),best.); pence=input(scan(put(num,best.),2,"."),best.); want=cat(strip(put(pounds,words23.))," pounds and ",strip(put(pence,words10.))," pence"); run;
I would skip the conversion of value to character etc.
29 data _null_;
30 do num=33.17;
31 l = int(num);
32 p = mod(num,l)*1e2;
33 put _all_;
34 end;
35 run;
num=33.17 l=33 p=17 _ERROR_=0 _N_=1
Then format with words.
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 16. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.