good day all,
can i separate a name by blank?
for example
Name
Liverpool Virgil van Dijk
separate a name by blank into 4 columns
column1 column2 column3 column4
Liverpool Virgil van Dijk
is there any way to do it?
thanks in advance
Regards,
Harry
Hi @harrylui
If you want to concatenate several columns using a blank as a delimiter, you can use the CATX function as suggested by @PeterClemmensen
/* Concatenate */
data have;
input column1:$30. column2:$30. column3:$30. column4:$30.;
datalines;
Liverpool Virgil van Dijk
;
run;
data want;
set have;
name = catx(" ",column1, column2, column3, column4);
run;
If you want to separate the words of a sting in as many columns, you can do this, using the COUNTW() and SCAN() function:
/* Separate */
data have;
input name $50.;
datalines;
Liverpool Virgil van Dijk
;
run;
proc sql noprint;
select max(countw(name)) into:max_count from have;
quit;
data want;
set have;
array column(&max_count) $ 30;
do i=1 to countw(name);
column(i) = scan(name,i," ");
end;
drop i;
run;
Best,
Sounds like a job for the CATX Function
Hi @harrylui
If you want to concatenate several columns using a blank as a delimiter, you can use the CATX function as suggested by @PeterClemmensen
/* Concatenate */
data have;
input column1:$30. column2:$30. column3:$30. column4:$30.;
datalines;
Liverpool Virgil van Dijk
;
run;
data want;
set have;
name = catx(" ",column1, column2, column3, column4);
run;
If you want to separate the words of a sting in as many columns, you can do this, using the COUNTW() and SCAN() function:
/* Separate */
data have;
input name $50.;
datalines;
Liverpool Virgil van Dijk
;
run;
proc sql noprint;
select max(countw(name)) into:max_count from have;
quit;
data want;
set have;
array column(&max_count) $ 30;
do i=1 to countw(name);
column(i) = scan(name,i," ");
end;
drop i;
run;
Best,
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.