Help using Base SAS procedures

REmoving interior Blanks

Reply
Occasional Contributor
Posts: 16

REmoving interior Blanks

I Have the following data set;

Data daset1;
Input location height;
cards;
A 0.2
A 0.8
B 0.1
.....
run;
I then use the following command to create a new column.

Data daset2;
set Dataset1;
locheight = location || height;
run;

The output is displayed below

location height locheight
A 0.2 A 0.2
A 0.8 A 0.8
B 0.1 B 0.1

Does anyone know how to remove the interior blanks on elements of locheight. That the output appears as folows:

location height locheight
A 0.2 A0.2
A 0.8 A0.8
B 0.1 B0.1
Super Contributor
Posts: 359

Re: REmoving interior Blanks

compress(location || height);
or
cats(location , height);
Occasional Contributor
Posts: 9

Re: REmoving interior Blanks

Sometimes trailing blanks are troublesome so try using TRIM.

concat = trim(var1) || var2; *---> trim removes trailing blanks;

another function you may find of interest...COMPRESS

concat = var1 || var2;
concat = compress(concat); *---> takes out internal spaces and other chars by default;
Frequent Contributor
Posts: 127

Re: REmoving interior Blanks

Hello,

You could also use the combination of the COMPBL and COMPRESS functions.
The first one will replace double blanks by a single blank whereas the second one will remove the single blanks from your variable.

e.g:

Data daset2;
set Dataset1;
locheight = compress(compbl(location || height));
run;


Regards,
Florent
Ask a Question
Discussion stats
  • 3 replies
  • 2184 views
  • 0 likes
  • 4 in conversation