<?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 into Variables without delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447644#M283357</link>
    <description>&lt;P&gt;It's possible that you already have an ideal solution in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;'s post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It depends on what form your various pieces of information are in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Your original string that needs to be split ... where is that string stored?&amp;nbsp; In what format (SAS data set? text?)&lt;/LI&gt;
&lt;LI&gt;Your information about where each field starts and how long it is ... is that stored in a file or is that on paper?&lt;/LI&gt;
&lt;LI&gt;Do you also have information about which fields are numeric and which are character?&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Similarly, do you have information about the proper variable name to use when reading in the data?&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 22 Mar 2018 00:48:29 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-03-22T00:48:29Z</dc:date>
    <item>
      <title>Splitting String into Variables without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447566#M283355</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help with splitting a string without a delimiter into multiples variables. So here is an example of the string that I have&lt;/P&gt;&lt;P&gt;ABC12345678910qwertyuiop&lt;/P&gt;&lt;P&gt;I want to split it into multiple variables, these variables have various predefined length themselves. Here is an example of the desired output:&lt;/P&gt;&lt;P&gt;Var1&amp;nbsp; Var2&amp;nbsp;&amp;nbsp;&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; .....&lt;/P&gt;&lt;P&gt;ABC 1234&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5678910&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; qwert &amp;nbsp;&amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the start position and length of each variable. So in the output above, Var2 starts from the 4th character and has 4 characters, Var3 starts from the 8th character and has 7 characters itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 20:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447566#M283355</guid>
      <dc:creator>TPhung</dc:creator>
      <dc:date>2018-03-21T20:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting String into Variables without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447620#M283356</link>
      <description>&lt;P&gt;If all of your data look like that then use the information to create a data step to read the data from the columns. The numbers below are the start and end columns each variable occupies. This could well be a tad easier than pulling apart a string and adding additional bits to create variables of the proper type. The $ tells SAS that the data read is character.&lt;/P&gt;
&lt;PRE&gt;data want;
   infile "filename";
   input 
      var1 $ 1-3
      var2 4-7
      var3 8-14
      var4 $ 15-24
   ;
run;&lt;/PRE&gt;
&lt;P&gt;If you have a document that tells you what columns the data occupy this is a nearly trivial exercise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have dates or times&amp;nbsp;then you likely want to specify an appropriate INFORMAT to tell SAS to read the data correctly. If you have values that are currency values like $12,345 then specify the comma or commax&amp;nbsp;informat to read values correctly.&lt;/P&gt;
&lt;P&gt;You can specify the format after the columns or in place of the column&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 22:59:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447620#M283356</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-21T22:59:21Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting String into Variables without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447644#M283357</link>
      <description>&lt;P&gt;It's possible that you already have an ideal solution in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;'s post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It depends on what form your various pieces of information are in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Your original string that needs to be split ... where is that string stored?&amp;nbsp; In what format (SAS data set? text?)&lt;/LI&gt;
&lt;LI&gt;Your information about where each field starts and how long it is ... is that stored in a file or is that on paper?&lt;/LI&gt;
&lt;LI&gt;Do you also have information about which fields are numeric and which are character?&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Similarly, do you have information about the proper variable name to use when reading in the data?&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 22 Mar 2018 00:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447644#M283357</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-22T00:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting String into Variables without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447727#M283358</link>
      <description>&lt;P&gt;Assuming that the data you have is already in a SAS dataset or a DBMS table, the way to split such a string is the SUBSTR function, e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Length
  Var1 $3
  Var2 $4
  Var3 $7
  ;
Var1=String;
Var2=substr(String,4);
Var3=substr(String,8);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note that when SAS copies strings, it just copies enough characters to fill up the receiving string, if that is shorter than the source. Which is why I just wrote "Var1=String" - when the length of Var1 is already set to 3 characters, only the first 3 characters of String will be written there. And this is also why I did not specify the length in the SUBSTR invocations (as in "Var2=substr(String,4,4)") - the length of the receiving variables is defined in the LENGTH statement. If&amp;nbsp;you do not use&amp;nbsp;the LENGTH statement first, all the variables declared by the SUBSTR function call will be 8. So it is better to declare the length first, and then call SUBSTR.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 11:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447727#M283358</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-03-22T11:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting String into Variables without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447751#M283359</link>
      <description>&lt;P&gt;The original strings to be splitted&amp;nbsp;are stored in a text file. I do have all the information about the data, in paper though.&lt;/P&gt;&lt;P&gt;It is something like this:&lt;/P&gt;&lt;P&gt;Item&amp;nbsp;&amp;nbsp;&amp;nbsp; Field&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Size&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Position&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Format&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Type&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; 3&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;&amp;nbsp; 1-3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHAR&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ID&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&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;&amp;nbsp;&amp;nbsp;4-8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHAR&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8&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;&amp;nbsp;&amp;nbsp; 9-17&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ZD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My assignment is to break down the string into these fields, I also have to assigned names to the variables as well as the original data does not have a header.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 12:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447751#M283359</guid>
      <dc:creator>TPhung</dc:creator>
      <dc:date>2018-03-22T12:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting String into Variables without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447806#M283360</link>
      <description>&lt;P&gt;Given that the information is on paper, you will need to work with the paper-based information to create an INPUT statement.&amp;nbsp; (Once you have the INPUT statement, building the rest of the DATA step is straightforward, but let me know if that is something you need help doing.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example based on the information you posted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;input @1 type&amp;nbsp;&amp;nbsp; $char3.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @4 ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $char4.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@5 Date&amp;nbsp;&amp;nbsp; ZD8.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to a bit about what goes into an INPUT statement.&amp;nbsp; For example, if you were just reading 3 characters from columns 25 to 27 to assign to a numeric variable, you might be using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;input &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/54795"&gt;@25&lt;/a&gt; numvar&amp;nbsp;&amp;nbsp; 3.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to understand what ZD means in your paper-based-instructions, and check the SAS instructions that would match.&amp;nbsp; Here, I assumed that SAS would use its ZD informat, but you would need to check the details on that.&amp;nbsp; (In the SAS documentation, look up INFORMATS.)&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 14:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-String-into-Variables-without-delimiter/m-p/447806#M283360</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-22T14:57:37Z</dc:date>
    </item>
  </channel>
</rss>

