DATA Step, Macro, Functions and more

Compressing spaces

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Compressing spaces

Hi,

I have a csv file:

 

 

01/02/2009,146,394
02/02/2009,278,791
03/02/2009,224,637
04/02/2009,275,725
05/02/2009,276,1 101
06/02/2009,247,1 103
07/02/2009,154,412
08/02/2009,192,609
09/02/2009,308,992
10/02/2009,333,1 287
11/02/2009,342,1 250
12/02/2009,375,1 975
13/02/2009,275,1 019
14/02/2009,120,487
15/02/2009,133,567
16/02/2009,210,770

 

 

I remove Â with the command 'compress', no problem.
But to remove the space, there is a problem, the command 'compress', does nothing.
Why?


My goal is not to change the csv file but to transform eg:

1Â 056   -- compress -->   1 056    --> compress -->  1056

 


data toto;
infile 'C:\.........................\sessionsetpagesvues.csv' dlm=',' firstobs=8 truncover;
input Index_des_jours :ddmmyy. Sessions :numx. x3 $;
x4=compress(x3,'Â ','a');
x5=compress(x4,'','s');
Pages_vues= input(x5, numx.);
run;

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


proc contents data=toto;run;

 

 

 

 

x5=compress(x4,'','s');

This command does not work why?


Thank you for your help.


Accepted Solutions
Solution
‎10-27-2016 05:28 PM
Respected Advisor
Posts: 3,799

Re: Compressing spaces

It's not a space '20'x it just looks like one.  It is non-breaking space 'A0'x.

View solution in original post


All Replies
Solution
‎10-27-2016 05:28 PM
Respected Advisor
Posts: 3,799

Re: Compressing spaces

It's not a space '20'x it just looks like one.  It is non-breaking space 'A0'x.

Regular Contributor
Posts: 175

Re: Compressing spaces

I'm not sure why that doesn't work, as that was my first answer.

 

Anyway, you can use Perl regular expressions like so:

 

data test;
    variable = "1 045";
    rid = prxparse('s/\s*//');
    call prxchange(rid, -1, variable);
    drop rid;
run;

Here are two references: [1], [2].

Super User
Super User
Posts: 7,997

Re: Compressing spaces

Just to add, the compress function has various modifiers you can apply to it which should simplfy your code:

x4=compress(x3,,'kd');

Note I put no characters in the second paramter, the 'KD' or keep decimals, does everything needed here.  For example:

data a;
  abcd="1Â 101";
  def=compress(abcd,,"kd");
run;
☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 255 views
  • 2 likes
  • 4 in conversation