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
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;
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;
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?
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 |
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.
SCAN() would be easier.
Wordnumber = scan('First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth',number);
This sounds like a homework assignment. :smileysilly:
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
A "correct answer" has been provided. Did it not work for you?
No
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.