converting numeric to character

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

converting numeric to character


Hello Everyone,

I have two files File_A and File_B. I need to merge both the files using a common variable "FIRM". The problem is that in file_A, FIRM is in character while in file_B, FIRM is in numeric. In addition, the length of FIRM in both the files is also different.

In file_A, the column attributes of FIRM is length 10; format $10; informat $10; type character.  FIRM in file_A look like the following

obs     FIRM

1     "0000001111"

2     "0000000020"

3     "0012345678"

In file_B, the column attributes of FIRM is length 8; format BEST 12; informat 12; type numeric. In other words, FIRM in file_B is reported as follows:

obs     FIRM

1     1111

2     20

3     12345678

Due to this difference, I am not able to merge the two data. I would appreciate if someone tell me how to make FIRM in file_B same as FIRM in file_A so that I could merge the two files?

Thank you for your time.


Accepted Solutions
Solution
‎06-08-2012 01:05 PM
Super Contributor
Posts: 1,636

Re: converting numeric to character

How about:

data firmb;
input firm;
cards;
1111
20
12345678
;

data firmb;
set firmb;
new_firm=put(firm,z10.);
proc print;run;

                                     obs        firm     new_firm

                                     1         1111    0000001111
                                     2           20    0000000020
                                     3     12345678    0012345678


Linlin


View solution in original post


All Replies
Solution
‎06-08-2012 01:05 PM
Super Contributor
Posts: 1,636

Re: converting numeric to character

How about:

data firmb;
input firm;
cards;
1111
20
12345678
;

data firmb;
set firmb;
new_firm=put(firm,z10.);
proc print;run;

                                     obs        firm     new_firm

                                     1         1111    0000001111
                                     2           20    0000000020
                                     3     12345678    0012345678


Linlin


Contributor
Posts: 28

Re: converting numeric to character

Thanks Linlin. It works.

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 242 views
  • 0 likes
  • 2 in conversation