07-05-2016 03:48 PM
In my data one variable name='CLIST' contains values of many variables.I need to create 11 variables from it; Please help. How to spilit the data. There are several subjects with different length of values with same order of values
1 ATC|N|NERVOUS SYSTEM; ATC|N06|PSYCHOANALEPTICS; ATC|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; ATC|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; PRODUCT|062107 01 001|ARMODAFINIL; PRODUCTSYNONYM|062107 01 002|NUVIGIL;
CMATC1C= 'NERVOUS SYSTEM';
CMATC3C='PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS';
CMATC4C='CENTRALLY ACTING SYMPATHOMIMETICS';
CMPNC='062107 01 001';
CMSYNC='062107 01 002';
07-05-2016 04:13 PM
If you have an idea what the maximumn length of any of the result variables is then specify that in a length statement, otherwise you "guess" and put that value in a length statement. Something like:
Length CMATC1C $ 25; if you think that CMATC1C should never exceed 25 characters.
If the data order is always the same then extracting the values like this should work with the length statements correct.
<length statements go here>
CMATC1 = scan(clist,2,'|;');
CMATC2 = scan(clist,5,'|;');
CMATC3 = scan(clist,8,'|;');
CMATC4 = scan(clist,11,'|;');
CMPNC = scan(clist,14,'|;');
CMPR = scan(clist,15,'|;');
CMSYNC = scan(clist,17,'|;');
CMSYN = scan(clist,18,'|;');
07-06-2016 02:25 PM
Thank you for the help. It worked for me. But for one clist value it didnot separate as I needed. In clist value, for variables CMATC1 to CMATC4, the ' ATC' is preceeding as I highlighted in red. For CMPNC and CMSYN,'PRODUCT' is preceding.
Your code worked for me for all observation except this clist value. This clist value has missing value for CMATC4 and CMATC4C. But for CMATC4 and CMATC4C the value of CMPNC is assinged. Please help
Clist=ATC|R|RESPIRATORY SYSTEM; ATC|R05|COUGH AND COLD PREPARATIONS; ATC|R05X|OTHER COLD PREPARATIONS; PRODUCT|000558 01 001|VICK VAPOUR-RUB;PRODUCTSYNONYM|000558 01 002|VICKS VAPORUB /00055801/;
"The clist values for which your code worked is =
clist=ATC|N|NERVOUS SYSTEM; ATC|N06|PSYCHOANALEPTICS; ATC|N06B|PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS; ATC|N06BA|CENTRALLY ACTING SYMPATHOMIMETICS; PRODUCT|062107 01 001|ARMODAFINIL; PRODUCTSYNONYM|062107 01 002|NUVIGIL;"