BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
WilliamB
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

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

paulkaefer
Lapis Lazuli | Level 10

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].

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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