BookmarkSubscribeRSS Feed
Statsconsultancy
Fluorite | Level 6
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
3 REPLIES 3
Flip
Fluorite | Level 6
compress(location || height);
or
cats(location , height);
jj030655
Calcite | Level 5
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;
Florent
Quartz | Level 8
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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 6048 views
  • 0 likes
  • 4 in conversation