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

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,

X1
Y2
Z3
A4
B5

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

X1One
Y2Two
Z3Three
A4Four
B5Five

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

1 ACCEPTED SOLUTION

Accepted Solutions
statistician13
Quartz | Level 8

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;

View solution in original post

10 REPLIES 10
statistician13
Quartz | Level 8

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;

ballardw
Super User

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?

SushilKumar
Calcite | Level 5

Thanks to every one,

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

X1First
Y2Second
Z3Third
A4Fourth
B5Fifth
Kurt_Bremser
Super User

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.

Tom
Super User Tom
Super User

SCAN() would be easier.

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


jaredp
Quartz | Level 8

This sounds like a homework assignment.  :smileysilly:

SushilKumar
Calcite | Level 5

jairedp you can easily convert this

X1First
Y2Second
Z3Third
A4Fourth
B5Fifth

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

jaredp
Quartz | Level 8

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

Kurt_Bremser
Super User

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

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 6515 views
  • 4 likes
  • 6 in conversation