Convert string'250 million' into a number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | *(Q) I have a string variable containing items such as 100 billion 250 million 7 billion I need to convert these to numbers. *I also have strings containing numbers with commas, I need to convert them to numbers. *(A) Posted to SPSSX-List by Raynald Levesque on 2003/04/02. DATA LIST FIXED /revenue 1-14(A) empl 15-20(A). BEGIN DATA 100 billion 10,500 250 million 500 7 billion 7,000 END DATA. COMPUTE #pos=INDEX(UPCASE(revenue),'BILLION'). IF #pos>0 revenue2=NUMBER(SUBSTR(revenue,1,#pos - 1),F8)*1000000000. COMPUTE #pos=INDEX(UPCASE(revenue),'MILLION'). IF #pos>0 revenue2=NUMBER(SUBSTR(UPCASE(revenue),1,#pos - 1),F8)*1000000. COMPUTE empl2=NUMBER(empl,COMMA8). EXECUTE. * Note that if billion or million are misspelled, the corresponding value of revenu2 will be missing, review any such cases. |
Related pages
...