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,
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.