<?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: How to parse string with no delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508125#M136428</link>
    <description>&lt;P&gt;this is &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; code modified for your needs noted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;. &amp;nbsp;FYI, record 2 fulfills your condition where a record may have more columns than expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input myVar $255.;
cards;
084375EJ9084375EK6084375EL4
084375EJ9082375EK6084325EL4084395EJ9084395EK6084395EL4
074375EJ9089375EK6084335EL4
064375EJ9084375EK6084345EL4
;;;;
run;
proc print data=have;
run;

data want; 
set have;
Obs = _n_; *record number to know which go together;
len = length(myVar); *legnth of variable to loop only as needed;

do i=1 to len by 9; *loop;
    value = substr(myVar, i, 9); * extract string of size 9 each time;
    output; *output;
end;
run;

*wide format;
proc transpose data=want out=wide prefix=VAR;
by Obs;
var value;
run;
proc print data=wide;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;output proc prints&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;The SAS System&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Obs myVar&lt;BR /&gt;1 084375EJ9084375EK6084375EL4&lt;BR /&gt;2 084375EJ9082375EK6084325EL4084395EJ9084395EK6084395EL4&lt;BR /&gt;3 074375EJ9089375EK6084335EL4&lt;BR /&gt;4 064375EJ9084375EK6084345EL4&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 28 Oct 2018 16:15:48 GMT</pubDate>
    <dc:creator>VDD</dc:creator>
    <dc:date>2018-10-28T16:15:48Z</dc:date>
    <item>
      <title>How to parse string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508079#M136399</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a string variable with a bunch of CUSIPs (9-digit bond IDs) strung together without any delimiter. Each observation in the column also&amp;nbsp;has different lengths, i.e., some observations have 2 bonds (18 characters) and others have up to 10 or more (90 characters). How do I create a new variable that puts each CUSIP into a separate column?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have an observation under the CUSIP column that has:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;084375EJ9084375EK6084375EL4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make new variables cusip1, cusip2, cusip3 with the values&amp;nbsp;084375EJ9, 084375EK6, 084375EL4 respectively?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Natee&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 03:49:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508079#M136399</guid>
      <dc:creator>sas123451</dc:creator>
      <dc:date>2018-10-28T03:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508080#M136400</link>
      <description>&lt;P&gt;Take&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s solution from this link unless you wanna play with APP functions like I(proud disciple of Paul Dorfman) do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507865#M136337" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Creating-an-incremented-variable-in-a-do-loop/m-p/507865#M136337&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 03:53:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508080#M136400</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-28T03:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508085#M136402</link>
      <description>&lt;P&gt;If you prefer to have each CUSIP as separate observation then you can try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename cusips '&amp;lt;path and name&amp;gt;' recfm=v;

data want;
   infile cussips;
   input cussip $9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Oct 2018 07:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508085#M136402</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-10-28T07:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508124#M136427</link>
      <description>&lt;P&gt;Thank you for your response. I do prefer to have each CUSIP as a separate observation but I do not completely understand your code. Would you mind annotating it?&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 15:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508124#M136427</guid>
      <dc:creator>sas123451</dc:creator>
      <dc:date>2018-10-28T15:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508125#M136428</link>
      <description>&lt;P&gt;this is &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; code modified for your needs noted by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;. &amp;nbsp;FYI, record 2 fulfills your condition where a record may have more columns than expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover;
input myVar $255.;
cards;
084375EJ9084375EK6084375EL4
084375EJ9082375EK6084325EL4084395EJ9084395EK6084395EL4
074375EJ9089375EK6084335EL4
064375EJ9084375EK6084345EL4
;;;;
run;
proc print data=have;
run;

data want; 
set have;
Obs = _n_; *record number to know which go together;
len = length(myVar); *legnth of variable to loop only as needed;

do i=1 to len by 9; *loop;
    value = substr(myVar, i, 9); * extract string of size 9 each time;
    output; *output;
end;
run;

*wide format;
proc transpose data=want out=wide prefix=VAR;
by Obs;
var value;
run;
proc print data=wide;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;output proc prints&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;The SAS System&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;Obs myVar&lt;BR /&gt;1 084375EJ9084375EK6084375EL4&lt;BR /&gt;2 084375EJ9082375EK6084325EL4084395EJ9084395EK6084395EL4&lt;BR /&gt;3 074375EJ9089375EK6084335EL4&lt;BR /&gt;4 064375EJ9084375EK6084345EL4&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 16:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508125#M136428</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-10-28T16:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse string with no delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508133#M136429</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&amp;nbsp;for your interest and perseverance. Well done!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 28 Oct 2018 17:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-parse-string-with-no-delimiter/m-p/508133#M136429</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-28T17:12:48Z</dc:date>
    </item>
  </channel>
</rss>

