<?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 one column values into seven columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/858003#M339003</link>
    <description>&lt;P&gt;If, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;suggested, the days are not always in the same order, you should look for the day identifier, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  set have;                                                                                                                             
  length sunday monday tuesday wednesday thursday friday saturday $ 20;                                                                 
  array outvar(*) sunday--saturday;                                                                                                     
  _N_=1;                                                                                                                                
  do day='sun','mon','tue','wed','thu','fri','sat';                                                                                     
    pos=findw(days,day,', ','i');                                                                                                       
    if pos then                                                                                                                         
      outvar(_N_)=scan(substr(days,pos),2,', ');                                                                                        
    _N_+1;                                                                                                                              
    end;                                                                                                                                
  drop day pos;                                                                                                                         
run;                                                                                                                                    
                  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Feb 2023 12:22:41 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-02-09T12:22:41Z</dc:date>
    <item>
      <title>Splitting one column values into seven columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/857933#M338981</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;One column that has weekdays, timings, and a delimiter . what I want to divide into seven columns based on the delimiter ,. Additionally, the values are separated by a comma. It was closed on some of the days.&lt;/P&gt;&lt;P&gt;The data I have looks like this:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;length days $200;&lt;BR /&gt;infile datalines truncover;&lt;BR /&gt;input days $ 1-200;&lt;BR /&gt;datalines;&lt;BR /&gt;Sun CLOSED, Mon 9:00AM-6:30PM, Tue 9:00AM-6:30PM, Wed 9:00AM-6:30PM, Thu 9:00AM-6:30PM, Fri 9:00AM-6:30PM, Sat 9:00AM-4:00PM,&lt;BR /&gt;Sun 10:00AM-9:00PM, Mon 8:00AM-9:00PM, Tue 8:00AM-9:00PM, Wed 8:00AM-9:00PM, Thu 8:00AM-9:00PM, Fri 8:00AM-9:00PM, Sat 8:00AM-9:00PM,&lt;BR /&gt;Sun CLOSED, Mon 8:00AM-5:00PM, Tue 8:00AM-5:00PM, Wed 8:00AM-5:00PM, Thu 8:00AM-5:00PM, Fri 8:00AM-5:00PM, Sat CLOSED,&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I want data as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cho16_0-1675919520271.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80260iED342887B8EA1256/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cho16_0-1675919520271.png" alt="cho16_0-1675919520271.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the below code&lt;/P&gt;&lt;P&gt;data want (drop=days);&lt;BR /&gt;set have;&lt;BR /&gt;Sunday = scan(days,1,',');&lt;BR /&gt;monday = scan(days,2,',');&lt;BR /&gt;tuesday = scan(days,3,',');&lt;BR /&gt;wednesday = scan(days,4,',');&lt;BR /&gt;thursday = scan(days,5,',');&lt;BR /&gt;friday = scan(days,6,',');&lt;BR /&gt;saturday = scan(days,7,',');&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 05:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/857933#M338981</guid>
      <dc:creator>cho16</dc:creator>
      <dc:date>2023-02-09T05:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one column values into seven columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/857936#M338983</link>
      <description>&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data want (drop=days);
set have;
length sunday monday tuesday wednesday thursday friday saturday $ 20;
Sunday    = scan( scan(days,1,','),2,' ');
monday    = scan( scan(days,2,','),2,' ');
tuesday   = scan( scan(days,3,','),2,' ');
wednesday = scan( scan(days,4,','),2,' ');
thursday  = scan( scan(days,5,','),2,' ');
friday    = scan( scan(days,6,','),2,' ');
saturday  = scan( scan(days,7,','),2,' ');
run;&lt;/PRE&gt;
&lt;P&gt;You have two pieces and even stated then, the "days" are separated by commas, but the TIME part is separated by a space inside the day value. So nesting the Scan function twice, the inner part gets the "day" of week and the second, using the space delimiter gets the time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the use of the Length statement to specify the length of the variables. If you don't use such you can have unexpected results of results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I'm not sure if I would trust such data to always be in order and assume that the 4th column is always Wednesday but would parse the values a bit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a likely a poor idea to store actual content (name of the day of the week) in a variable name but you don't indicate what this will be used for later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 05:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/857936#M338983</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-09T05:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one column values into seven columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/858003#M339003</link>
      <description>&lt;P&gt;If, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;suggested, the days are not always in the same order, you should look for the day identifier, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;                                                                                                                              
  set have;                                                                                                                             
  length sunday monday tuesday wednesday thursday friday saturday $ 20;                                                                 
  array outvar(*) sunday--saturday;                                                                                                     
  _N_=1;                                                                                                                                
  do day='sun','mon','tue','wed','thu','fri','sat';                                                                                     
    pos=findw(days,day,', ','i');                                                                                                       
    if pos then                                                                                                                         
      outvar(_N_)=scan(substr(days,pos),2,', ');                                                                                        
    _N_+1;                                                                                                                              
    end;                                                                                                                                
  drop day pos;                                                                                                                         
run;                                                                                                                                    
                  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Feb 2023 12:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/858003#M339003</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-09T12:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one column values into seven columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/858005#M339004</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;says: "&lt;SPAN&gt;It is a likely a poor idea to store actual content (name of the day of the week) in a variable name but you don't indicate what this will be used for later." I would agree, and I advise&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73714"&gt;@cho16&lt;/a&gt;&amp;nbsp;not to do this, and to explain why the data is needed in this form. From everything I know about SAS, data is almost never needed in this form, most (all?) SAS PROCs are designed to work with data in the long form. Arranging data with columns whose names are Monday, Tuesday, &lt;EM&gt;etc.&lt;/EM&gt; just makes programming the next step harder.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 12:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-one-column-values-into-seven-columns/m-p/858005#M339004</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-09T12:35:38Z</dc:date>
    </item>
  </channel>
</rss>

