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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 5726 views
  • 0 likes
  • 4 in conversation