Dear ,
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
eg:
Subject clist
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;
output needed:
CMATC1C= 'NERVOUS SYSTEM';
CMATC1='N';
CMATC2C='PSYCHOANALEPTICS';
CMATC2='N06';
CMATC3C='PSYCHOSTIMULANTS, AGENTS USED FOR ADHD AND NOOTROPICS';
CMATC3='N06B';
CMATC4C='CENTRALLY ACTING SYMPATHOMIMETICS';
CMATC4='N06BA';
CMPR='ARMODAFINIL';
CMPNC='062107 01 001';
CMSYNC='062107 01 002';
'CMSYN='NUVIGIL';
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.
data want;
set have;
<length statements go here>
CMATC1 = scan(clist,2,'|;');
CMATC1C= scan(clist,3,'|;');
CMATC2 = scan(clist,5,'|;');
CMATC2C= scan(clist,6,'|;');
CMATC3 = scan(clist,8,'|;');
CMATC3C= scan(clist,9,'|;');
CMATC4 = scan(clist,11,'|;');
CMATC4C= scan(clist,12,'|;');
CMPNC = scan(clist,14,'|;');
CMPR = scan(clist,15,'|;');
CMSYNC = scan(clist,17,'|;');
CMSYN = scan(clist,18,'|;');
run;
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;"
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.