<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Data stored in one cell delimiting issues in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954791#M372878</link>
    <description>&lt;P&gt;anyone familiar with data all stored in one cell with delimiters and successfully breaking them down into their own cell?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, we have all drugs that the patient started on in one cell in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isoniazid[1] | Rifampin[2] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Rifapentine[6] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a blank within the repeating block, no data will be written into the repeating block like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isoniazid[1] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my issue is creating a repeating block that will split the cells that have missing information like above;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;%macro repeating_block (input=have&lt;/DIV&gt;&lt;DIV&gt;var=Drug,&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;output=want) ;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sql noprint;&lt;/DIV&gt;&lt;DIV&gt;select max(countw(Drug_ALL,'|')) into : max from have;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data want;&lt;/DIV&gt;&lt;DIV&gt;set have;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array drug_{&amp;amp;max} $ 100;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array iteration{&amp;amp;max}8 _temporary_ ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do i=1 to &amp;amp;max;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;drug_clean=scan(drug_all, i, '|');&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if drug_clean ne '' then do;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;drug=scan(drug_clean, 1, '[');&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;iter_num=input(scan(scan(Drug_clean,2,'['), 1, ']'), 8.);&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if iter_num&amp;gt;0 and iter_num&amp;lt;=&amp;amp;max then do;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;Deug_[iter_num]=trim (drug);&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;iteration[iter_num] = iter_num;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if drug_clean='' then drug_[iter_num]="";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;drop&amp;nbsp; iter_num drug_clean&amp;nbsp; i;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;%mend repeating_block;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%repeating_block;&lt;/DIV&gt;</description>
    <pubDate>Mon, 30 Dec 2024 20:41:29 GMT</pubDate>
    <dc:creator>mly</dc:creator>
    <dc:date>2024-12-30T20:41:29Z</dc:date>
    <item>
      <title>Data stored in one cell delimiting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954791#M372878</link>
      <description>&lt;P&gt;anyone familiar with data all stored in one cell with delimiters and successfully breaking them down into their own cell?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, we have all drugs that the patient started on in one cell in this format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isoniazid[1] | Rifampin[2] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Rifapentine[6] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If there is a blank within the repeating block, no data will be written into the repeating block like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Isoniazid[1] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my issue is creating a repeating block that will split the cells that have missing information like above;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;%macro repeating_block (input=have&lt;/DIV&gt;&lt;DIV&gt;var=Drug,&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;output=want) ;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sql noprint;&lt;/DIV&gt;&lt;DIV&gt;select max(countw(Drug_ALL,'|')) into : max from have;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data want;&lt;/DIV&gt;&lt;DIV&gt;set have;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array drug_{&amp;amp;max} $ 100;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array iteration{&amp;amp;max}8 _temporary_ ;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do i=1 to &amp;amp;max;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;drug_clean=scan(drug_all, i, '|');&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if drug_clean ne '' then do;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;drug=scan(drug_clean, 1, '[');&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;iter_num=input(scan(scan(Drug_clean,2,'['), 1, ']'), 8.);&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if iter_num&amp;gt;0 and iter_num&amp;lt;=&amp;amp;max then do;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;Deug_[iter_num]=trim (drug);&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;iteration[iter_num] = iter_num;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if drug_clean='' then drug_[iter_num]="";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;drop&amp;nbsp; iter_num drug_clean&amp;nbsp; i;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;%mend repeating_block;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%repeating_block;&lt;/DIV&gt;</description>
      <pubDate>Mon, 30 Dec 2024 20:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954791#M372878</guid>
      <dc:creator>mly</dc:creator>
      <dc:date>2024-12-30T20:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Data stored in one cell delimiting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954795#M372881</link>
      <description>&lt;P&gt;I don't really follow the language you are using.&amp;nbsp; CELL is something I would use when referring to part of Excel Worksheet, not anything to do with actual datasets or variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What result do want from these two observations you shared?&lt;/P&gt;
&lt;PRE&gt;Isoniazid[1] | Rifampin[2] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Rifapentine[6] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]
Isoniazid[1] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]&lt;/PRE&gt;
&lt;P&gt;To me they both appear to be lists of pairs of values delimited with | character.&amp;nbsp; Where the pairs of values consists of a string followed by a number in square brackets.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  row+1;
  input drug_all $200.;
datalines;
Isoniazid[1] | Rifampin[2] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Rifapentine[6] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]
Isoniazid[1] | Pyrazinamide[3] | Ethambutol[4] | Streptomycin[5] | Ethionamide[7] | Amikacin[8] | Kanamycin[9] | Streptomycin[10]
;

data want;
   set have;
   length pair $100 drug $100 position 8 ;
   do index=1 to countw(drug_all,'|');
      pair = left(scan(drug_all,index,'|'));
      drug = scan(pair,1,'[');
      position = input(scan(pair,-1,'[ ]'),32.);
      output;
   end;
   drop drug_all pair;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1735601589542.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103411i09DE7157BC406727/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1735601589542.png" alt="Tom_0-1735601589542.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If for some reason you need to convert it into something less useful for analysis but easier to dump into spreadsheet then perhaps you could use PROC TRANSPOSE?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=want out=wide(drop=_name_) prefix=drug;
  by row;
  id position;
  var drug;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1735601913933.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103412i9A1CAE4B51414ADB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1735601913933.png" alt="Tom_0-1735601913933.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 23:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954795#M372881</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-12-30T23:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Data stored in one cell delimiting issues</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954798#M372883</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I'm not sure why this is in a Macro program and I don't have a clear picture of your input data and your desired output. However, it seems to me that you have named the array as "D&lt;STRONG&gt;&lt;FONT color="#339966"&gt;R&lt;/FONT&gt;&lt;/STRONG&gt;UG_" but then later in the program, you refer to the array item as "D&lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt;E&lt;/FONT&gt;&lt;/STRONG&gt;UG_".&lt;/P&gt;
&lt;P&gt;&amp;nbsp; What do you see in the SAS log after you run this code? Can you post a better example of what you expect your output to look like. It seems to me that all you really want to do is put each drug into a numbered variable, where the number for any drug corresponds to the number in [] as in. But you only show one "cell" of data. Are the numbers in brackets always in order, as you show? Or, could the numbers in the brackets be out of order like this:&lt;/P&gt;
&lt;P&gt;"Isoniazid[1] | Rifampin[2] | Streptomycin[4] | Montelukast[3]"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Is it possible for something like this to happen where there are only 10 drugs listed but the numbers in the brackets are more than 10? This could cause issues if your array is defined only to have 10 members, but your program tries to write to a member greater than 10:&lt;/P&gt;
&lt;P&gt;Isoniazid[11] | Rifampin[12] | Pyrazinamide[13] | Ethambutol[14] | Streptomycin[15] | Rifapentine[16] | Ethionamide[17] | Amikacin[18] | Kanamycin[19] | Streptomycin[20]&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I don't really understand the data and the desired results well enough to comment in more detail. My first suggestion is to fix the typo in the code. As always with Macro programs, my first suggestion is to always start with a working program that is NOT in a macro definition and make sure your program logic works correctly first before macro-izing your program.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Dec 2024 01:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-stored-in-one-cell-delimiting-issues/m-p/954798#M372883</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-12-31T01:23:45Z</dc:date>
    </item>
  </channel>
</rss>

