<?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: Seperate a string into different columns using a delimiter in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712975#M27103</link>
    <description>&lt;PRE&gt;data want;
   Set have;
   array Col_(4) $ 10 ;
   do i =1 to dim(Col_);
      Col_(i) = scan(string, i, ":");
   drop i;
   end;
run;&lt;/PRE&gt;&lt;P&gt;Regarding this solution, I have different column names and the data length is $1000&lt;/P&gt;&lt;P&gt;so the modified code will be as below, correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;Set have;&lt;/P&gt;&lt;P&gt;array A B C D $1000 ; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;------- These are different column names. They are all different.&lt;/P&gt;&lt;P&gt;do i =1 to dim(Col_);&lt;/P&gt;&lt;P&gt;Col_(i) = scan(string, i, ":");&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not get any error, I get the data in the below format. I get the 2nd and 4th part of the string correctly but for 1st and 3rd part, I see dot (.) symbol.&lt;/P&gt;&lt;P&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3547264 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 74635&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;857373382 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;827374928&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Jan 2021 05:10:08 GMT</pubDate>
    <dc:creator>SAS_New_User1</dc:creator>
    <dc:date>2021-01-21T05:10:08Z</dc:date>
    <item>
      <title>Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712971#M27100</link>
      <description>&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;I have a data string separated by a ":" colon delimiter. I want to separate the strings separated by delimiter into different columns in data set&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;string&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;:57D:3547264:56D:74635:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;:52A:857373382:73D:827374928:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;Desired Output&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;col_1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; col_2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; col_3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; col_4&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;57D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3547264&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 56D &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 74635&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;52A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 857373382&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 73D&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 827374928&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;I used scan function as below, but it did not work.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;data have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;array parse(*) col_1 col_2 col_3 col_4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;do i =1 to dim(parse);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;parse(i) = scan(string, i, ":");&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;drop i;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;run;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 04:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712971#M27100</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-21T04:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712972#M27101</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string :$50.;
datalines; 
:57D:3547264:56D:74635:      
:52A:857373382:73D:827374928:
;

data long;
   set have;
   n = _N_;
   do i = 1 to countw(string, ':');
      w = scan(string, i, ':');
      if w ne '' then output;
   end;
run;

proc transpose data = long out = want(drop=_:) prefix=col_;
   by n;
   id i;
   var w;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jan 2021 04:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712972#M27101</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-01-21T04:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712973#M27102</link>
      <description>&lt;P&gt;Did your log show anything about character to numeric conversion?&lt;/P&gt;
&lt;P&gt;Your array Parse is defined as numeric.&lt;/P&gt;
&lt;P&gt;So you can't put values like "57D" into it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code you show has no source either, should be as SET HAVE, not DATA HAVE.&lt;/P&gt;
&lt;P&gt;Try:&lt;/P&gt;
&lt;PRE&gt;data want;
   Set have;
   array Col_(4) $ 10 ;
   do i =1 to dim(Col_);
      Col_(i) = scan(string, i, ":");
   drop i;
   end;
run; &lt;/PRE&gt;
&lt;P&gt;The 10 on the Array&amp;nbsp; is the length of each character variable created. If your data may be longer than increase the size.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I am making new variables I just use the base of the name in the array definition. You didn't provide any example of other variables that might be in your data so if the variables Col_1 etc. exist already they need to be character variables and could use your array statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 04:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712973#M27102</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-21T04:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712975#M27103</link>
      <description>&lt;PRE&gt;data want;
   Set have;
   array Col_(4) $ 10 ;
   do i =1 to dim(Col_);
      Col_(i) = scan(string, i, ":");
   drop i;
   end;
run;&lt;/PRE&gt;&lt;P&gt;Regarding this solution, I have different column names and the data length is $1000&lt;/P&gt;&lt;P&gt;so the modified code will be as below, correct?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;Set have;&lt;/P&gt;&lt;P&gt;array A B C D $1000 ; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;------- These are different column names. They are all different.&lt;/P&gt;&lt;P&gt;do i =1 to dim(Col_);&lt;/P&gt;&lt;P&gt;Col_(i) = scan(string, i, ":");&lt;/P&gt;&lt;P&gt;drop i;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not get any error, I get the data in the below format. I get the 2nd and 4th part of the string correctly but for 1st and 3rd part, I see dot (.) symbol.&lt;/P&gt;&lt;P&gt;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3547264 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 74635&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;857373382 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;827374928&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 05:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712975#M27103</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-21T05:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712992#M27104</link>
      <description>&lt;P&gt;Are you reading a sas data set or an external file?&lt;/P&gt;
&lt;P&gt;If it is an external file, like .csv or .txt you can define the delimiter in the infile staement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;infile "&amp;lt;path and filename&amp;gt;" dlm=':' &amp;lt;more options&amp;gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and then&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input col1 $ col2 col3 $ col 4;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 07:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712992#M27104</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-21T07:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712993#M27105</link>
      <description>You even can define more than one delimiter like:&lt;BR /&gt;   dlm=' ,:' - means: either space or comma or colon.</description>
      <pubDate>Thu, 21 Jan 2021 07:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/712993#M27105</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-01-21T07:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/713096#M27113</link>
      <description>Hi Shmuel,&lt;BR /&gt;I am reading a sas data set.</description>
      <pubDate>Thu, 21 Jan 2021 15:47:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/713096#M27113</guid>
      <dc:creator>SAS_New_User1</dc:creator>
      <dc:date>2021-01-21T15:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Seperate a string into different columns using a delimiter</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/713119#M27115</link>
      <description>&lt;P&gt;Your ARRAY statement is wrong. Has the LENGTH definition in the wrong place.&amp;nbsp; Plus it is defining an array named A but the DO loop is looking for an array named COL_.&lt;/P&gt;
&lt;P&gt;The length you set in the array is the length you want to use to define the new variables. Most likely that will be much shorter than the full 1,000 characters in the source string.&lt;/P&gt;
&lt;P&gt;Do you know the maximum number of values that any given string could have?&amp;nbsp; If you use this ARRAY method then you need define enough variables to hold all of the values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string :$1000. ;
cards4;
:57D:3547264:56D:74635:
:52A:857373382:73D:827374928:
;;;;

data want ;
  set have ;
  array new $32 a b c d ;
  do i=1 to min(dim(new),countw(string,':'));
    new[i] = scan(string,i,':');
  end;
  drop i;
run;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs               string                 a         b         c     d

 1     :57D:3547264:56D:74635:          57D    3547264      56D    74635
 2     :52A:857373382:73D:827374928:    52A    857373382    73D    827374928
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jan 2021 16:28:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Seperate-a-string-into-different-columns-using-a-delimiter/m-p/713119#M27115</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-21T16:28:19Z</dc:date>
    </item>
  </channel>
</rss>

