<?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: Splitting into rows and columns help? in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672363#M32153</link>
    <description>&lt;P&gt;My apologies for the confusion--and thank you for your patience. I imported the data from Excel, but to give an idea of what it would look like for the first rows (noting the datalines are messed up by the string):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; help;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;infile&lt;/SPAN&gt; datalines &lt;SPAN class="s2"&gt;dlm&lt;/SPAN&gt;=&lt;SPAN class="s3"&gt;','&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;input&lt;/SPAN&gt; ID string;&lt;/P&gt;&lt;P class="p2"&gt;datalines&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;1234,000004|load|||||| / 001135|on|974|544|Notes|Region2| / 001159|off|950|516|Notes|Region2| / 001160|on|950|516|Notes|Region4| / 001177|off|927|489|Notes|Region4| / 001178|on|927|489|Notes|Region1| / 001183|off|915|475|Notes|Region1|&lt;/P&gt;&lt;P class="p1"&gt;2345,000006|load|||||| / 002003|on|897|562|Notes|Region3| / 002019|off|886|546|Notes|Region3| / 002021|on|886|546|Notes|Region2| / 002042|off|873|526|Notes|Region2| / 002044|on|873|526|Notes|Region4| / 002130|off|858|501|Notes|Region4| /&lt;/P&gt;&lt;P class="p1"&gt;3456,000007|load|||||| / 000490|on|784|575|Notes|Region3| / 000524|off|762|537|Notes|Region3| / 000525|on|762|537|Notes|Region2| / 000890|off|734|538|Notes|Region2| /&lt;/P&gt;&lt;P class="p1"&gt;4567,000007|load|||||| / 000864|on|1014|552|Notes|Region2| / 001047|off|1016|541|Notes|Region2| /&lt;/P&gt;&lt;P class="p1"&gt;;&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;Yes--and thank you, that works for splitting each section (e.g.,&amp;nbsp;001135|on|974|544|Notes|Region2|) into separate variables. I had also split up the preceding text string into separate rows at the / using:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; want;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt;&amp;nbsp;have ;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;do&lt;/SPAN&gt; i=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;by&lt;/SPAN&gt; &lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;while&lt;/SPAN&gt;(scan(oldstring,i,&lt;SPAN class="s4"&gt;'/'&lt;/SPAN&gt;)^=&lt;SPAN class="s4"&gt;' '&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class="p1"&gt;string=scan(oldstring,i,&lt;SPAN class="s4"&gt;'/'&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class="p2"&gt;output&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;end&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s5"&gt;My apologies for any&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 26 Jul 2020 01:56:51 GMT</pubDate>
    <dc:creator>esw1</dc:creator>
    <dc:date>2020-07-26T01:56:51Z</dc:date>
    <item>
      <title>Splitting into rows and columns help?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672355#M32149</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to parse some text in a particular way. I have a bunch of data where each rows has something like:&lt;/P&gt;&lt;P&gt;000006|load|||||| / 000194|on|794|417|Notes|Region2| / 000244|off|768|383|Notes|Region2| / 000244|on|768|383|Notes|Region3| / 000395|off|700|358|Notes|Region3| /&lt;/P&gt;&lt;P&gt;Sometimes this goes on for longer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is it possible to split this into a) rows in which I have each pair of on and off in one row with all of the text between | among columns (so it's easy to compute differences between some of the numeric variables for each on/off), and b) different rows after each instance of on and off (so after, for example, Region2| / appears twice)? &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jul 2020 23:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672355#M32149</guid>
      <dc:creator>esw1</dc:creator>
      <dc:date>2020-07-25T23:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting into rows and columns help?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672357#M32150</link>
      <description>&lt;P&gt;Are you reading from a text file or is this data already in a SAS dataset?&amp;nbsp; If the later is it in one variable?&lt;/P&gt;
&lt;P&gt;Is there a pattern?&amp;nbsp; Looks like you have groups of 6 or 7 values separated by pipes and the group are separated by slashes.&amp;nbsp; So something like this:&lt;/P&gt;
&lt;PRE&gt;000006|load|||||| / 
000194|on|794|417|Notes|Region2| / 
000244|off|768|383|Notes|Region2| / 
000244|on|768|383|Notes|Region3| / 
000395|off|700|358|Notes|Region3| /&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Jul 2020 00:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672357#M32150</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-26T00:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting into rows and columns help?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672358#M32151</link>
      <description>&lt;P&gt;It's already in a SAS dataset loaded from an Excel file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The two columns that exist are a unique identifier and a column with all of these entries (can call the variable to_split), with 200 rows (where the text length can be slightly different for each row).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But yes, the pattern is that the first row will be the load, and then every set of two rows is an on then an off.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 00:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672358#M32151</guid>
      <dc:creator>esw1</dc:creator>
      <dc:date>2020-07-26T00:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting into rows and columns help?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672360#M32152</link>
      <description>&lt;P&gt;It is still really hard to tell what you actually have. Please post a data step that creates a few example rows of your starting data. It would also help if you posted a data step that creates the results you want from that example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you have two variables and you want to convert it into 7 variables instead. SCAN() is probably what you want to use.&amp;nbsp; You didn't say what your variables are called or what you want the variables to be called.&amp;nbsp; So let's assume they are named ID and STRING.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  length var1 $8 var2 $8 var3 var4 8 var5 $100 var6 $20 ;
   var1=scan(string,1,'|','mq');
   var2=scan(string,2,'|','mq');
   var3=input(scan(string,3,'|','mq'),32.);
   var4=input(scan(string,4,'|','mq'),32.);
   var5=scan(string,5,'|','mq');
   var6=scan(string,6,'|','mq');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Jul 2020 01:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672360#M32152</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-26T01:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting into rows and columns help?</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672363#M32153</link>
      <description>&lt;P&gt;My apologies for the confusion--and thank you for your patience. I imported the data from Excel, but to give an idea of what it would look like for the first rows (noting the datalines are messed up by the string):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; help;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;infile&lt;/SPAN&gt; datalines &lt;SPAN class="s2"&gt;dlm&lt;/SPAN&gt;=&lt;SPAN class="s3"&gt;','&lt;/SPAN&gt;;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;input&lt;/SPAN&gt; ID string;&lt;/P&gt;&lt;P class="p2"&gt;datalines&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;1234,000004|load|||||| / 001135|on|974|544|Notes|Region2| / 001159|off|950|516|Notes|Region2| / 001160|on|950|516|Notes|Region4| / 001177|off|927|489|Notes|Region4| / 001178|on|927|489|Notes|Region1| / 001183|off|915|475|Notes|Region1|&lt;/P&gt;&lt;P class="p1"&gt;2345,000006|load|||||| / 002003|on|897|562|Notes|Region3| / 002019|off|886|546|Notes|Region3| / 002021|on|886|546|Notes|Region2| / 002042|off|873|526|Notes|Region2| / 002044|on|873|526|Notes|Region4| / 002130|off|858|501|Notes|Region4| /&lt;/P&gt;&lt;P class="p1"&gt;3456,000007|load|||||| / 000490|on|784|575|Notes|Region3| / 000524|off|762|537|Notes|Region3| / 000525|on|762|537|Notes|Region2| / 000890|off|734|538|Notes|Region2| /&lt;/P&gt;&lt;P class="p1"&gt;4567,000007|load|||||| / 000864|on|1014|552|Notes|Region2| / 001047|off|1016|541|Notes|Region2| /&lt;/P&gt;&lt;P class="p1"&gt;;&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s4"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s4"&gt;Yes--and thank you, that works for splitting each section (e.g.,&amp;nbsp;001135|on|974|544|Notes|Region2|) into separate variables. I had also split up the preceding text string into separate rows at the / using:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; want;&lt;SPAN class="s2"&gt;set&lt;/SPAN&gt;&amp;nbsp;have ;&lt;/P&gt;&lt;P class="p1"&gt;&lt;SPAN class="s2"&gt;do&lt;/SPAN&gt; i=&lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;by&lt;/SPAN&gt; &lt;SPAN class="s3"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;while&lt;/SPAN&gt;(scan(oldstring,i,&lt;SPAN class="s4"&gt;'/'&lt;/SPAN&gt;)^=&lt;SPAN class="s4"&gt;' '&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class="p1"&gt;string=scan(oldstring,i,&lt;SPAN class="s4"&gt;'/'&lt;/SPAN&gt;);&lt;/P&gt;&lt;P class="p2"&gt;output&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p2"&gt;end&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN class="s5"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="p3"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="p3"&gt;&lt;SPAN class="s5"&gt;My apologies for any&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jul 2020 01:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/Splitting-into-rows-and-columns-help/m-p/672363#M32153</guid>
      <dc:creator>esw1</dc:creator>
      <dc:date>2020-07-26T01:56:51Z</dc:date>
    </item>
  </channel>
</rss>

