Change 1Â 056 ---> 1056

Posts: 33

Change 1Â 056 ---> 1056


I have a excel table and for the thousands I have a "Â" and therefore I would like to remove the "Â" to keep numeric variables without changing the .xlsx file.
My goal transform this: 056                           

988       -->  988
056 ---> 1056

 Sometimes, there is no "Â":



179253231 208
179332761 101
179342471 103
179383331 287
179393421 250
179403751 975
179412751 019









I should probably create a informat?


Finally, the last line is the total of columns 2.3.

Here is the false start code.

data toto;
infile 'C:\.........\SPV11.xlsx' dlm=',' firstobs=8 truncover;
input x1 :ddmmyy. x2 :numx.  x3 :numx.;

proc print data=toto(obs=350);run;




Attachements: my .xlsx file.


Is there any simple solution to those operations? Thank you!

Super User
Super User
Posts: 9,599

Re: Change 1Â 056 ---> 1056

Personally I would fix this in the XLS file - why can you not fix the file you have, if its wrong then not chaning it there will cause more issues further down the line - always try to fix things "at source".  If that is not possible then copy the file, find and replace in the new file, and use that - oh, make sure you do a QC on that.  You can also do it in SAS - assuming that SAS actually reads in that character - you can use the tranwrd() function to perform a find and replace.  I can;t provide any exact code as I don;t download Excel files, but it is very simple, just follow the guidance on the SAS pages:

Super User
Posts: 6,785

Re: Change 1Â 056 ---> 1056

If the data can't be changed in Excel, you will need to read those fields into SAS as character.  Having done that,  you could try:


field = compress(field, , 'kd');


That will keep only the digits.  So it will get rid of anything else such as decimal points, negative signs ... anything that is not a digit.  If that is not sufficient for  your needs, take a look at some of the additional options that are permissible within the third parameter of the COMPRESS function.  It can be done, but first you have to decide which characters (in addition to digits) you wish to keep.

Super User
Posts: 10,280

Re: Change 1Â 056 ---> 1056

If that code:

data toto;
infile 'C:\.........\SPV11.xlsx' dlm=',' firstobs=8 truncover;
input x1 :ddmmyy. x2 :numx.  x3 :numx.;

actually worked, your file is not an Excel file at all, since infile and input only work on text files. XLSX files are zip-compressed XML and can't be read into SAS like this.

Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 3 replies
  • 4 in conversation