BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

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';

            

 

 

2 REPLIES 2
ballardw
Super User

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;

knveraraju91
Barite | Level 11

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;"

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 825 views
  • 2 likes
  • 2 in conversation