<?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 do we create column from string where '\' is used to separate the sub string in SAS ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259510#M269020</link>
    <description>&lt;P&gt;I'm not sure this handles everything you see in your data, but the right tool to split up the text is the SCAN function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;long_string = "&lt;STRONG&gt;prexa\Medical Information\Medical";&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;col1 = scan(long_string, 1, '\');&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;col2 = scan(long_string, 2, '\');&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;col3 = scan(long_string, 3, '\');&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2016 00:42:53 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-03-29T00:42:53Z</dc:date>
    <item>
      <title>How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259509#M269019</link>
      <description>&lt;P&gt;I have been trying to create columns in sas based on substring. I need to create a coloumn of each sub string stored in a column seprated by '\'. For example:-&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;prexa\Medical Information\Medical&lt;/STRONG&gt; Letters 02 is a single string stored in one column. i would like to have three columns col1: &lt;STRONG&gt;prexa&lt;/STRONG&gt; col2 :&lt;STRONG&gt;Medical Information&lt;/STRONG&gt; and Col3 : &lt;STRONG&gt;Medical&lt;/STRONG&gt;. I am new to sas and have tried but unable to proceed.&lt;/P&gt;&lt;P&gt;this column has numeric values with no sub string as well.&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2500iA092DEB28A6D7EEE/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Content of Column.png" title="Content of Column.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 00:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259509#M269019</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T00:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259510#M269020</link>
      <description>&lt;P&gt;I'm not sure this handles everything you see in your data, but the right tool to split up the text is the SCAN function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;long_string = "&lt;STRONG&gt;prexa\Medical Information\Medical";&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;col1 = scan(long_string, 1, '\');&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;col2 = scan(long_string, 2, '\');&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;col3 = scan(long_string, 3, '\');&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 00:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259510#M269020</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-29T00:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259511#M269021</link>
      <description>Thanks a lot for your reply. I have used scan function but the data just not contain 3 substring but multiple substring( shared just snapshot of data in image) . I am dealing with 100,000+ observations so I need to have something that can be dynamic. I have been thinking of using do while loop while putting substring function having '\' something similar. Can you please suggest ? Thanks again.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Mar 2016 00:49:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259511#M269021</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T00:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259512#M269022</link>
      <description>&lt;P&gt;And to populate the numeric variable you can add this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  NUM=input(LONG_STRING, ?? dollar32.);
  if NUM=. then do;
    COL1 = scan(LONG_STRING, 1, '\');
    COL2 = scan(LONG_STRING, 2, '\');
    COL3 = scan(LONG_STRING, 3, '\');
  end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:41:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259512#M269022</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-03-29T01:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259514#M269023</link>
      <description>Thanks a lot for your reply. I have used scan function but the data just not contain 3 substring but multiple substring( shared just snapshot of data in image) . I am dealing with 100,000+ observations so I need to have something that can be dynamic. I have been thinking of using do while loop while putting substring function having '\' something similar. Can you please suggest ? Thanks again.&lt;BR /&gt;</description>
      <pubDate>Tue, 29 Mar 2016 00:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259514#M269023</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T00:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259515#M269024</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array COL [99] $32;               
  NUM=input(LONG_STRING, ?? dollar32.);       
  if NUM=. then do I=1 to 99 until (COL[I]='');
    COL[I] = scan(LONG_STRING, I, '\');      
  end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Edited: I&amp;nbsp;had the informat name wrong&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259515#M269024</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-03-29T01:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259521#M269025</link>
      <description>thanks a lot. can you please help me understand. NUM=input(LONG_STRING, ?? $32.); I understand input function but can you please explain the role of "??". i have never used it.</description>
      <pubDate>Tue, 29 Mar 2016 01:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259521#M269025</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T01:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259534#M269026</link>
      <description>&lt;P&gt;The number of observations isn't so important. &amp;nbsp;It's the variables that matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider skipping functions entirely and just using "\" as a delimiter when reading in the variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;infile rawdata dlm="\" dsd;&lt;/P&gt;
&lt;P&gt;input col1 $ col2 $ col3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you have to figure out where all the variables are. &amp;nbsp;It won't do to figure out 3 at a time.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259534#M269026</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-29T01:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259537#M269027</link>
      <description>&lt;P&gt;Look up the input function documentation, it's all there. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259537#M269027</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2016-03-29T01:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259545#M269028</link>
      <description>&lt;P&gt;thanks a lot. i will look into this. really Appericiate your help.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259545#M269028</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T01:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259548#M269029</link>
      <description>&lt;P&gt;its not raw data file but a coloum with a string. and its substring are seprated by '/'. thanks again for all your help.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 01:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259548#M269029</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T01:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259560#M269030</link>
      <description>&lt;P&gt;So given that you have a SAS data set with a single variable in it, what do you want the outcome to be at the end of all the processing?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 02:18:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259560#M269030</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-03-29T02:18:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259616#M269031</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well the first question you should be asking yourself is what is this data, how did I arrive with it. Now I do not know what the numbers are but the other part looks like some sort of directory listing. &amp;nbsp;Is this data you have created? &amp;nbsp;If so I would fix the code which generates this data, if it comes from a vendor then update your agreement so the data is in a useable format. &amp;nbsp;Without knowledge of what the data is or how you came by it something like the below code might help, it creates a series of character variales for each split of the long string - note I do not do any conversions to number or anything else, just split the string up. &amp;nbsp;The reason is I do not know this data, nor what its used for. &amp;nbsp;99% of any programming task is to understand your data and arrange that in a manner which is conducive to programming, the example data you provided looks like at least two different data items appended to each other - this is generally not good. &amp;nbsp;Also, please post test data in the form of a datastep as text in your posts, its not great to have to type all that in to test code:&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines dlm="¬";
  length long_string $2000;
  input long_string $;
datalines;
6
7
3
4
P Toolbox\Customer program\peer to peer
abc\ert\popt\abcdedgeg\defty
;
run;

proc sql noprint;
  select  max(countw(LONG_STRING,"\"))
  into    :NUM_ARRAY
  from    HAVE;
quit;

data want;
  set have;
  array col{&amp;amp;num_array.} $100;
  do i=1 to countw(long_string,"\");
    col{i}=scan(long_string,i,"\");
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2016 08:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259616#M269031</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-29T08:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259690#M269032</link>
      <description>&lt;P&gt;SHOW what your expected output should look like.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 14:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259690#M269032</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-29T14:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259907#M269033</link>
      <description>&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2544i15ACA7DB92C650DA/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Basic Idea.jpg" title="Basic Idea.jpg" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variable has long string and has to be divided into substrings and divided into columns of substrings. At the end we need to have total for each observation which has total for each populated coloumn. I hope i cleared it. Thanks for all the help.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259907#M269033</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T22:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259909#M269034</link>
      <description>&lt;P&gt;Thanks for the solution.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2016 22:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259909#M269034</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T22:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do we create column from string where '\' is used to separate the sub string in SAS ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259910#M269035</link>
      <description>Thanks for the solution.</description>
      <pubDate>Tue, 29 Mar 2016 22:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-we-create-column-from-string-where-is-used-to-separate/m-p/259910#M269035</guid>
      <dc:creator>vinayakraja</dc:creator>
      <dc:date>2016-03-29T22:24:56Z</dc:date>
    </item>
  </channel>
</rss>

