Help using Base SAS procedures

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

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

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,

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


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

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


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

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;

Super User
Posts: 10,819

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

X1First
Y2Second
Z3Third
A4Fourth
B5Fifth
Super User
Posts: 7,092

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;

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 6,681

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

X1First
Y2Second
Z3Third
A4Fourth
B5Fifth

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

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

No

Super User
Posts: 7,092

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
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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