'Is there any specific way for using substring and concatenation together in SAS array?
I am having issue with this. The values in Col: are all of same length.The problem is that after running this only the last value(of col10) is getting populated. Other values are not getting concatenated. Is there any other way to this? Thanks in advance..
array Test $ COL1-COL10;
do over Test;
if Test ne "" then result = catx(",",substr(Test,4,6));
end;
Solution 1:[1]
Behaviour seems correct/expected. Since you never concatenate the result values together it overwrites itself each time and only the last result will remain.
You likely want something closer to:
array Test $ COL1-COL10;
length result $45.;*make long enough to hold results;
result = '';
do over Test;
if Test ne "" then result = catx(",", result, substr(Test,4,6));
end;
And personally, I find arrays with indexes much easier to understand.
array Test $ COL1-COL10;
length result $45.;*make long enough to hold results;
result = '';
do i=1 to dim(test);
if not missing(Test(i)) then result = catx(",", result, substr(Test(i),4,6));
end;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
