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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

8 REPLIES 8
AshokD
Obsidian | Level 7

@RW9

 

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.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

AshokD
Obsidian | Level 7
Thanks for your help and time.
PeterClemmensen
Tourmaline | Level 20

Just to be clear, is Amount a numeric variable?

AshokD
Obsidian | Level 7

@PeterClemmensen

 

yes , Amount is a numeric variable

PeterClemmensen
Tourmaline | Level 20

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; 
data_null__
Jade | Level 19

@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.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 1522 views
  • 5 likes
  • 4 in conversation