turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- How to convert 1 as one and 2 as two without Proc ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-13-2014 05:10 AM

Hi,

Could any one help me how to convert Numeric Value 1 as **one** and 2 as **two** and 3 as **three............ etc without using Proc Format **

for egi do have dataset like,

X | 1 |

Y | 2 |

Z | 3 |

A | 4 |

B | 5 |

and i want dataset to be like below without using **Proc Format **

X | 1 | One |

Y | 2 | Two |

Z | 3 | Three |

A | 4 | Four |

B | 5 | Five |

and also is it possible to convert 1as First and 2 as Second and 3 as Third etc without using Proc Format

Accepted Solutions

Solution

02-13-2014
11:50 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-13-2014 11:50 AM

How about this:

data work.temp;

input letter $ number;

cards;

X 1

Y 2

Z 3

A 4

B 5

;

run;

data work.temp;

set work.temp;

wordnumber=put(number, words23.);

run;

proc print data=work.temp;

run;

All Replies

Solution

02-13-2014
11:50 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-13-2014 11:50 AM

How about this:

data work.temp;

input letter $ number;

cards;

X 1

Y 2

Z 3

A 4

B 5

;

run;

data work.temp;

set work.temp;

wordnumber=put(number, words23.);

run;

proc print data=work.temp;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-13-2014 11:55 AM

By "without proc format" do you mean without a custom format?

I think the easiest for the first requirement would be

data want;

set have;

/* assumes value is the name of the variable that contains the numeric 1,2,3 etc*/

num = put(value,words10.);

run;

If you somehow happen to find a dataset with the values and words you need you could use either a hash table or sql to match and bring in the word.

WHY can't you use proc format?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-19-2014 01:46 AM

Thanks to every one,

Could anyone help me is it possible to convert one as First and 2 as Second and goes on

X | 1 | First |

Y | 2 | Second |

Z | 3 | Third |

A | 4 | Fourth |

B | 5 | Fifth |

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-19-2014 03:17 AM

If the range of input values is a) numeric with constant intervals and b) rather small, you could do the following:

data xxx (drop=lookup);

set yyy;

retain lookup 'First Second Third Fourth Fifth Sixth SeventhEighth Ninth Tenth ';

Wordnumber = substr(lookup,(number-1)*7+1,7);

run;

Adjust the formula in the substr() to your actual needs.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-19-2014 10:13 AM

SCAN() would be easier.

Wordnumber = scan('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth',number);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

02-19-2014 01:12 PM

This sounds like a homework assignment. :smileysilly:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-15-2014 01:09 AM

jairedp you can easily convert this

X | 1 | First |

Y | 2 | Second |

Z | 3 | Third |

A | 4 | Fourth |

B | 5 | Fifth |

If you have 22 ,56 99 etc how will display that in words like twentytwo, fiftysix,lke that

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

05-15-2014 10:46 AM

A "correct answer" has been provided. Did it not work for you?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-02-2014 07:16 AM

No

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-02-2014 08:00 AM

You can either:

- use proc format to specify a custom label for all the values you intend to cover

- generate a lookup table with the labels and join your dataset with it

- use the same lookup table as input for a hash object and use that in the data step

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers