<?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 string variable into Multiple Column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256554#M268917</link>
    <description>&lt;P&gt;Why do you have data like that in one variable? &amp;nbsp;It sounds like you have imported some data? &amp;nbsp;If so why not fix the import step, i.e. use # as another delimiter, and this removes the need for the additional step?&lt;/P&gt;</description>
    <pubDate>Mon, 14 Mar 2016 14:23:07 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-03-14T14:23:07Z</dc:date>
    <item>
      <title>Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256539#M268913</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a problem with my dataset. My dataset is presented as follows:&lt;/P&gt;
&lt;P&gt;VAR&lt;/P&gt;
&lt;P&gt;--------&lt;/P&gt;
&lt;P&gt;1300456#GFA1#2000-11-13#GTO#1455667&lt;/P&gt;
&lt;P&gt;1300457#GFA2#2000-11-14#GTO#1455721&lt;/P&gt;
&lt;P&gt;1305515#GFA10#2000-11-20#EXP#5154155&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what I want to achieve is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;VAR1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR3&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; VAR4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR5&lt;/P&gt;
&lt;P&gt;1300456&amp;nbsp;&amp;nbsp;&amp;nbsp; GFA1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000-11-13&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GTO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1455667&lt;/P&gt;
&lt;P&gt;1300457&amp;nbsp;&amp;nbsp;&amp;nbsp; GFA2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2000-11-14&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GTO&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1455721&lt;/P&gt;
&lt;P&gt;1305515&amp;nbsp;&amp;nbsp;&amp;nbsp; GFA10&amp;nbsp;&amp;nbsp; 2000-11-20&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXP&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5154155&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, I just want to separate/ split one variable into multiple variables. I have tried the following code:&lt;/P&gt;
&lt;P&gt;Numerous ways to do what you want.&amp;nbsp; e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want (drop=_: i);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have (rename=(var=_var));&lt;/P&gt;
&lt;P&gt;&amp;nbsp; array var(5);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; i=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; do until (scan(_var,i,"#") eq "");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var(i)=scan(_var,i,"#");&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Source:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Splitting-Text-into-different-variables-columns/td-p/59964" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Splitting-Text-into-different-variables-columns/td-p/59964&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this syntax failed to take into account the string text in VAR2, the calendar date form in VAR3, and another string text in VAR4 (i.e., it captures only the numerical data). Can anyone help me with this? Greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 13:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256539#M268913</guid>
      <dc:creator>DavidLie</dc:creator>
      <dc:date>2016-03-14T13:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256543#M268914</link>
      <description>&lt;P&gt;Your array is declared as numeric. Add a $ sign after the array statement to create a character array instead that will hold string values.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Array var(5) $12. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Mar 2016 13:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256543#M268914</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-14T13:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256544#M268915</link>
      <description>&lt;P&gt;In this case, you need to define all of your new variables as Char, then convert them if needed during downstrem process, try add:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array var(5) $ 20;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Mar 2016 13:40:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256544#M268915</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-03-14T13:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256550#M268916</link>
      <description>&lt;P&gt;If you want two of your variables to be numeric, you can't put all the variables into the same array.&amp;nbsp; With only 5 variables, just hard-code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length var1 $ 7&amp;nbsp;&amp;nbsp; var2 $ 4&amp;nbsp;&amp;nbsp; var4 $ 3;&amp;nbsp;&amp;nbsp; /* or, possibly, select more appropriate lengths */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var1 = scan(var, 1, '#');&lt;/P&gt;
&lt;P&gt;var2 = scan(var, 2, '#');&lt;/P&gt;
&lt;P&gt;var3 = input(scan(var, 3, '#'), yymmdd10.);&lt;/P&gt;
&lt;P&gt;format var3 yymmdd10.;&lt;/P&gt;
&lt;P&gt;var4 = scan(var4, 4, '#');&lt;/P&gt;
&lt;P&gt;var5 = input(scan(var, 5, '#'), 8.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If VAR1 should also be numeric, that could follow a similar pattern as VAR5.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is possible that there are missing values (and thus two consecutive ##) in your data, SCAN should support an option that allows two consecutive # characters to be treated as separate delimiters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 14:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256550#M268916</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-14T14:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256554#M268917</link>
      <description>&lt;P&gt;Why do you have data like that in one variable? &amp;nbsp;It sounds like you have imported some data? &amp;nbsp;If so why not fix the import step, i.e. use # as another delimiter, and this removes the need for the additional step?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2016 14:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256554#M268917</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-14T14:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256675#M268918</link>
      <description>&lt;PRE&gt;data have;&lt;BR /&gt;input var $80.;&lt;BR /&gt;cards;&lt;BR /&gt;1300456#GFA1#2000-11-13#GTO#1455667&lt;BR /&gt;1300457#GFA2#2000-11-14#GTO#1455721&lt;BR /&gt;1305515#GFA10#2000-11-20#EXP#5154155&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data temp;&lt;BR /&gt; set have;&lt;BR /&gt; n+1;&lt;BR /&gt; do i=1 to countw(var,'#');&lt;BR /&gt; v=scan(var,i,'#','m');output;&lt;BR /&gt; end;&lt;BR /&gt; drop i;&lt;BR /&gt;run;&lt;BR /&gt;proc transpose data=temp out=want(drop=_: n) prefix=var;&lt;BR /&gt;by n;&lt;BR /&gt;var v;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Mar 2016 01:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256675#M268918</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-03-15T01:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting string variable into Multiple Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256749#M268919</link>
      <description>&lt;P&gt;This looks more like reading from infile than spltting a column. &amp;nbsp;(Same thing I reckon). &amp;nbsp;Infile magic is a handy alternative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input var $80.;
   cards;
1300456#GFA1#2000-11-13#GTO#1455667
1300457#GFA2#2000-11-14#GTO#1455721
1305515#GFA10#2000-11-20#EXP#5154155
;;;;
   run;
proc print;
   run;
data want;
   infile cards dsd dlm='#';
   if _n_ eq 1 then input @@;
   set have;
   _infile_ = var;
   input @1 id:$7. gaf:$4. date:yymmdd. var4:$4. var5 @@;
   format date yymmdd10.;
   cards;
Necessary evil
   run;
proc print;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/2312iE43D47D1ECAB65DB/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 17:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-string-variable-into-Multiple-Column/m-p/256749#M268919</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-06-30T17:02:43Z</dc:date>
    </item>
  </channel>
</rss>

