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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—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
  • 6618 views
  • 0 likes
  • 4 in conversation