Hi,
I have a data set where I have two codes in the same column:
I would like to split the two codes in two distinct lines, having into acount that the other attributes don't change. For example:
SRV_ERROR_CODE DESC_ERRO_SERVIC SMI_ERROR_CODE ERROR_CODE_SMI SMI_STATE SRV
50070 Subprocesso O... 30089 30089 PRBL TER
50070 Subprocesso O... 30089 30089 PRBL TER
Is there any SAS function that doses this?
Sometimes I have two codes to split, sometimes 3 codes, sometimes 4... I don't have any exact rule...
Thank you!
Rita Viegas
Code or task?
Are all of the codes 5 characters or less?
Assuming a single code in that field appears as |30089| then this code should work. I have no ideas for task approaches:
data want;
set have;
/* the length below needs to be at least as large as
your current code variable; 48 should work for up to
8 code values
*/
length oldcode $ 48.;
retain oldcode;
oldcode = code;
do i=1 to ( countw(oldcode,'|') -1);
code = scan(oldcode,i,'|');
output;
end;
drop oldcode i;
run;
The loop counter has -1 because your last delimiter | actually does not appear to have a value after it, so the count returned by COUNTW is one too large.
This would split the numbers:
...
* For a code segment of 5 characters;
do i = 2 to length( SMI_ERROR_CODE ) by 6;
SMI_ERROR_CODE_new = substr( SMI_ERROR_CODE, i, 4 )
output;
end;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.