<?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 Re: Separate data from one column to multiple columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270436#M53738</link>
    <description>&lt;P&gt;Hi Ballardw,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your kind reply. Actually this is the real data what you are seeing. If you want to manipulate it to facilitate analysis, please go ahead. I will follow your path. My target is to get separate reports which are existing in a single report in merged form.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 May 2016 19:39:40 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2016-05-13T19:39:40Z</dc:date>
    <item>
      <title>Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270390#M53717</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I have a dataset in which each row is having multiple sections. I want to create separate columns for each section. As the delimiters are varying in different rows such as 1), 2) , 3) , 1. 2. 3. &amp;nbsp;A) , B) , C) etc., I am struggling to separate it. Can somebody help me to solve the issue. Thank you in advance for your kind reply. Sas code is given below to give an idea of the existence of records:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
REPORT= "1) POLYP AT LEFT COLON: TUBULOVILLOUS. NEGATIVE FOR SERRATED.
2) POLYP AT RIGHT COLON: INFLAMMATORY. NEGATIVE FOR TUBULOVILLOUS. 
3. ADENOMA AT RIGHT COLON: INFLAMMATORY. NEGATIVE FOR TUBULOVILLOUS. 
4. ADENOMA FROM TRANSVERSE COLON: NEGATIVE FOR INFLAMMATORY BUT SERRATED IS FOUND.
A) ADENOMATOUS TISSUE AT LEFT COLON: TUBULOVILLOUS. NEGATIVE FOR SERRATED.
B) ADENOMATOUS TISSUE AT RIGHT COLON: INFLAMMATORY. NEGATIVE FOR TUBULOVILLOUS. 
A. POLYP FROM TRANSVERSE COLON: NEGATIVE FOR INFLAMMATORY BUT SERRATED IS FOUND.
B. POLYP AT LEFT COLON: TUBULOVILLOUS. NEGATIVE FOR SERRATED."
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 15:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270390#M53717</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-13T15:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270391#M53718</link>
      <description>&lt;P&gt;Are you importing this from a text file? Can you correct it in the import step?&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 15:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270391#M53718</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-13T15:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270395#M53720</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the inconvenience. What you are seeing is just a single record having 8 lines.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 16:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270395#M53720</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-13T16:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270407#M53726</link>
      <description>&lt;P&gt;Your posted data contains linefeed or carriage returns between what I believe you want for your new variables. Does your actual data contain those characters? That would be the easiest thing to split on if so.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 17:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270407#M53726</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-13T17:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270408#M53727</link>
      <description>&lt;P&gt;I understand that. My question is how did you get the data in the first place. Sometimes its easier to manipulate and make changes in the original data import step rather than afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you want your output to look like?&lt;/P&gt;
&lt;P&gt;Do all your questions have the exact same structure or do they vary, number of sections/delimiters.&lt;/P&gt;
&lt;P&gt;Do any responses have character ")" or can that be used as a delimiter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Take a look at the SCAN(), SUBSTR() functions for a start.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 17:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270408#M53727</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-05-13T17:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270435#M53737</link>
      <description>&lt;P&gt;Hi reeza,&lt;/P&gt;&lt;P&gt;I want each section of my report in a separate column. For e.g. in this record , there are 8 lines, so I want each line in a separate column. The&amp;nbsp;&lt;SPAN&gt;character ")" &amp;nbsp;can that be used as a delimiter. The&amp;nbsp;number of sections/delimiters may vary but I have different types of variation, I came across such as 1) 2) 3) 1. 2. 3. a. b. c. a) b) c).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;sorry to provide you a messy record on Friday.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Deepak&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 19:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270435#M53737</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-13T19:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270436#M53738</link>
      <description>&lt;P&gt;Hi Ballardw,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your kind reply. Actually this is the real data what you are seeing. If you want to manipulate it to facilitate analysis, please go ahead. I will follow your path. My target is to get separate reports which are existing in a single report in merged form.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 19:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270436#M53738</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-13T19:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270449#M53744</link>
      <description>&lt;P&gt;There is an issue that sometimes what is posted is not actually the content of the data after being filtered through the forum paste and copy to my side. I see a linebreak but that could be caused by more than one character and depending on the original file source could be a carriage return/line feed pair of characters, a single&amp;nbsp;line feed, a single&amp;nbsp;carriage return, and possibly even a vertical tab. But when pasting into the SAS editor it "fixes" things so that those characters are treated differently. So testing code is difficult.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure there is some slick way with regular expressions to do this but I don't work with them often.&lt;/P&gt;
&lt;P&gt;This MIGHT help but this is untested because of the issue above.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA TEST;
   set have; /* your dataset*/
/* assumes there are never more than 10 substatements increase the 10 if that is not the case. The substatments have to be long enough to the 
the longest substatement, the 700 should be as long as the length of the REPORT variable*/
   length tstr s1-s10 $ 700;   
   tstr = report; /* going to be slicing up things, don't want to lose orgininal data*/
   array s $ s1-s10;/* the 10 matches the 10 in the Length*/
   i = 1;
   do while (tstr ne '');
      pos = anycntrl(tstr); /*look for control characters*/
      /* when none then there should not be a line break*/
      if pos  = 0 then do ;
         s[i]=tstr;
         tstr='';
      end;
      /* when a linebreak is found, keep the string up to that position
      and remove that portion from the temporary string*/
      else do;
         s[i]= substr(tstr,1,pos-1);
         tstr= substr(tstr,pos+1);
      end;
      i=i+1;
   end;
   drop pos i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 21:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270449#M53744</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-13T21:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270494#M53754</link>
      <description>&lt;PRE&gt;
That is really not easy. There are too many patterns you need to consider about .



DATA TEST;
REPORT= "1) POLYP AT LEFT COLON: TUBULOVILLOUS. NEGATIVE FOR SERRATED.
 2) POLYP AT RIGHT COLON: INFLAMMATORY. NEGATIVE FOR TUBULOVILLOUS. 
 3. ADENOMA AT RIGHT COLON: INFLAMMATORY. NEGATIVE FOR TUBULOVILLOUS. 
 4. ADENOMA FROM TRANSVERSE COLON: NEGATIVE FOR INFLAMMATORY BUT SERRATED IS FOUND.
 A) ADENOMATOUS TISSUE AT LEFT COLON: TUBULOVILLOUS. NEGATIVE FOR SERRATED.
 B) ADENOMATOUS TISSUE AT RIGHT COLON: INFLAMMATORY. NEGATIVE FOR TUBULOVILLOUS. 
 A. POLYP FROM TRANSVERSE COLON: NEGATIVE FOR INFLAMMATORY BUT SERRATED IS FOUND.
 B. POLYP AT LEFT COLON: TUBULOVILLOUS. NEGATIVE FOR SERRATED."
;
RUN;
data temp;
 set test;
 do i=1 to countw(report,' ');
  temp=scan(report,i,' ');
  if prxmatch('/^(\d+|[a-z])\W$/i',strip(temp)) then n+1;
  output;
 end;
 keep n temp;
run;
data want;
 set temp;
 by n;
 length want $ 32767;
 retain want;
 want=catx(' ',want,temp);
 if last.n then do;output;call missing(want);end;
 drop temp;
 run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 May 2016 07:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270494#M53754</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-14T07:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270696#M53825</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly accept my apology for the delayed reply. The solution provided by you is simply great ! The different sections present in my report can be separated easily into multiple rows. &amp;nbsp;Is it possible to shift different section to new coulmns from the begining. (inspite of using proc transpose after the code provided by you. I am just curious; otherwise the solution provided for this critical situation is awesome.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 14:10:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270696#M53825</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-16T14:10:36Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270698#M53827</link>
      <description>&lt;P&gt;Hi Ballardw,&lt;/P&gt;&lt;P&gt;Everytime I go through your reply, I learn something new. I get a new direction to think about my issue. Thank you for your incredible replies.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using the code provided, I generated the output and attached for your kind consideration to get future direction as I am interested to address this issue using method other than regular expression.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your kind reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 14:25:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270698#M53827</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-16T14:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270722#M53833</link>
      <description>&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all, I want to thank you for providing me a great solution for a very critical issue related to my dataset having multiple reports merged together into a single report.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use the code provided by you to my dataset having multiple patients. I am experiencing difficulty in splitting the reports per patient. I have attached a sample for your kind consideration. Can you kindly guide me further.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in adavance for your kind guidance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 16:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270722#M53833</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-16T16:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270834#M53855</link>
      <description>&lt;P&gt;OK. no problem. Just add "patient_id" into group variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='/folders/myfolders/test1.xlsx' out=test dbms=xlsx replace;
run;
data temp;
 set test;
 do i=1 to countw(report,' ');
  temp=scan(report,i,' ');
  if prxmatch('/^(\d+|[a-z])\W$/i',strip(temp)) then n+1;
  output;
 end;
 keep patient_id n temp;
run;
data want;
 set temp;
 by patient_id  n;
 length want $ 32767;
 retain want;
 want=catx(' ',want,temp);
 if last.n then do;output;call missing(want);end;
 drop temp;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 May 2016 01:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270834#M53855</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-17T01:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270961#M53889</link>
      <description>&lt;P&gt;Good morning Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your incredible reply. For your kind information, I am trying to identify the number of sections existing in each report per person. Using the existing code, I am getting a number which reflects the overall count of sections. For your kind understanding, I have attached an excel sheet reflecting my needs. This is needed to get an idea about the number of reports belonging to each patient as well as different id can be allotted by concatenating patient id with the serial number.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once again thank you in advance with an expectation to get another invaluable tips from you which will be a life time experience as usual.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 12:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/270961#M53889</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-05-17T12:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Separate data from one column to multiple columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/271146#M53943</link>
      <description>&lt;P&gt;OK. Add one more statement ( n=0; ) into it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='/folders/myfolders/test1.xlsx' out=test dbms=xlsx replace;
run;
data temp;
 set test;
 n=0;
 do i=1 to countw(report,' ');
  temp=scan(report,i,' ');
  if prxmatch('/^(\d+|[a-z])\W$/i',strip(temp)) then n+1;
  output;
 end;
 keep patient_id n temp;
run;
data want;
 set temp;
 by patient_id  n;
 length want $ 32767;
 retain want;
 want=catx(' ',want,temp);
 if last.n then do;output;call missing(want);end;
 drop temp;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 May 2016 00:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Separate-data-from-one-column-to-multiple-columns/m-p/271146#M53943</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-18T00:57:32Z</dc:date>
    </item>
  </channel>
</rss>

