Hello,
I'm trying to parse a column called LINE that is delimited by spaces(' ').
Example records:
somedata1 somedata2
somedata1 somedata2 somedata3
somedata1
somedate1 somedate2 somedate3 somedate4
The number of delimiters is unknown. To handle this I'm taking the max count of spaces:
proc sql noprint;
select max(countc(LINE,' ')) + 1 into: nums
from testdata;
quit;
I would like to create additional columns with a prefix of col_ for the max number of delimiters found in the LINE column. So far I have the following code but it's not quite working.
data test;
set mydata;
%macro cols;
%do i = 1 %to &nums;
col_&i = scan(LINE, &nums, ' ');
%end;
%mend cols;
%cols;
run;
I would expect the Test dataset to contain 4 additional columns called Col_1, Col_2, Col_3, and Col_4; each containing the delimited values from LINE.
Put another way:
Col_1 will contain the values equal to somedata1
Col_2 will contain the values equal to somedata2
Col_3 will contain the values equal to somedata3
Col_4 will contain the values equal to somedata4
The results are getting close to the requirements but I'm missing something; its not quite right. I havent coded in SAS in a few years beyond simple CRUD stuff and am quite rusty.
Appreciate any help with this, thanks!
... View more