Solved
Contributor
Posts: 32

# How to convert 1 as one and 2 as two without Proc format

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
Contributor
Posts: 57

## Re: How to convert 1 as one and 2 as two without Proc format

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
Contributor
Posts: 57

## Re: How to convert 1 as one and 2 as two without Proc format

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;

Super User
Posts: 13,523

## Re: How to convert 1 as one and 2 as two without Proc format

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?

Contributor
Posts: 32

## Re: How to convert 1 as one and 2 as two without Proc format

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
Super User
Posts: 10,237

## Re: How to convert 1 as one and 2 as two without Proc format

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;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 8,092

## Re: How to convert 1 as one and 2 as two without Proc format

SCAN() would be easier.

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

Contributor
Posts: 71

## Re: How to convert 1 as one and 2 as two without Proc format

This sounds like a homework assignment.  :smileysilly:

Contributor
Posts: 32

## Re: How to convert 1 as one and 2 as two without Proc format

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

Contributor
Posts: 71

## Re: How to convert 1 as one and 2 as two without Proc format

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

Contributor
Posts: 32

No

Super User
Posts: 10,237

## Re: How to convert 1 as one and 2 as two without Proc format

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
How to convert datasets to data steps
How to post code
🔒 This topic is solved and locked.