<?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 break up a long character variable into individual (shorter) variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739068#M230624</link>
    <description>&lt;P&gt;First really determine need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SCAN function can use a specific delimiter to be used in getting the strings separated by that character.&lt;/P&gt;
&lt;P&gt;Countw can tell you how many sets of characters you have to process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines missover;
   input x $35.;
   array w {3} $ 20;
   do i=1 to countw(x,';');
      w[i]= scan(x,i,';');
   end;
   drop i;
datalines4;
This; is sometext;separated 
More text; two substrings
;more interesting; set of words
;;;;&lt;/PRE&gt;
&lt;P&gt;The array is a simple way to define the new variables by name, creating W1, W2 and W3, setting the length for the variables at 20 characters each. The Do loop shows one way to process this.&lt;/P&gt;</description>
    <pubDate>Tue, 04 May 2021 20:40:32 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-04T20:40:32Z</dc:date>
    <item>
      <title>How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739058#M230620</link>
      <description>&lt;P&gt;Hello. I have data sets with a long character variable (Longvar) that I want to split into 3 shorter character variables (Var1 Var2 Var3) . I might have more than 3 (depending on the data set I am working with) but to make it simple I will go with 3. For example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;subj&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Longvar&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;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; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "I need; to create; 3 short variables"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;I need&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;to create&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 short variables&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "Must; create; three short variables"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Must&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; three short variables&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note how what is actually written varies, depending on the subject, but I was hoping that the semicolon would be all I needed to be able to split the string - not matter what is written after the semicolon. I know this can be done in SPSS, but I can't seem to find the equivalent in SAS.&lt;/P&gt;&lt;P&gt;What would be the most effective way to do this in SAS?. And, if it can be done, could I create more than 3 variables. Is there a max limit ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739058#M230620</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T20:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739060#M230621</link>
      <description>&lt;P&gt;First, let's confirm whether you really need to do this.&amp;nbsp; PROC REPORT has a "wrap" option that will take long text and print it in as many lines as are needed.&amp;nbsp; So what do you gain by splitting the text yourself?&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739060#M230621</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-05-04T20:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739065#M230622</link>
      <description>&lt;P&gt;I need them to be separate variables that will be used in analysis. A lot of these will be numbers.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739065#M230622</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T20:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739066#M230623</link>
      <description>SCAN() is the function you're looking for. You can create as many variable as you want but you need to know the maximum ahead of time. If you don't, you either do it in multiple steps or you create a row for each value and then transpose it afterwards which is a fully dynamic solution that doesn't require any information ahead of time.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 04 May 2021 20:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739066#M230623</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-04T20:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739068#M230624</link>
      <description>&lt;P&gt;First really determine need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SCAN function can use a specific delimiter to be used in getting the strings separated by that character.&lt;/P&gt;
&lt;P&gt;Countw can tell you how many sets of characters you have to process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example:&lt;/P&gt;
&lt;PRE&gt;data example;
   infile datalines missover;
   input x $35.;
   array w {3} $ 20;
   do i=1 to countw(x,';');
      w[i]= scan(x,i,';');
   end;
   drop i;
datalines4;
This; is sometext;separated 
More text; two substrings
;more interesting; set of words
;;;;&lt;/PRE&gt;
&lt;P&gt;The array is a simple way to define the new variables by name, creating W1, W2 and W3, setting the length for the variables at 20 characters each. The Do loop shows one way to process this.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739068#M230624</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-04T20:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739074#M230626</link>
      <description>&lt;P&gt;Thank you. I am not familiar with Scan.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And what I can find is this (please see below). Do I have to write each String? This can't be it though, because it creates only one variable Word.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;Set have;&lt;/P&gt;&lt;P&gt;keep count word;&lt;BR /&gt;length word $30;&lt;BR /&gt;string=',leading, trailing,and multiple,,delimiters,,';&lt;BR /&gt;delim=',';&lt;BR /&gt;modif='mo';&lt;BR /&gt;nwords=countw(string, delim, modif);&lt;BR /&gt;do count=1 to nwords;&lt;BR /&gt;word=scan(string, count, delim, modif);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739074#M230626</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T20:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739078#M230627</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
longvar = "I need; to create; 3 short variables"; output;
longvar="Must; create; three short variables"; output;
run;

data long;
set have;
ID = _n_;
nTerms = count(longVar, ";")+1;

do i=1 to nTerms;
phrase = scan(longVar, i, ";");
output;
end;
run;

proc transpose data=long out=wide;
by ID;
var phrase;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello. I have data sets with a long character variable (Longvar) that I want to split into 3 shorter character variables (Var1 Var2 Var3) . I might have more than 3 (depending on the data set I am working with) but to make it simple I will go with 3. For example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;subj&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Longvar&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;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; &amp;nbsp; &amp;nbsp; &amp;nbsp;Var3&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "I need; to create; 3 short variables"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;I need&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;to create&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 short variables&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; "Must; create; three short variables"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Must&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; three short variables&lt;/P&gt;
&lt;P&gt;etc&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note how what is actually written varies, depending on the subject, but I was hoping that the semicolon would be all I needed to be able to split the string - not matter what is written after the semicolon. I know this can be done in SPSS, but I can't seem to find the equivalent in SAS.&lt;/P&gt;
&lt;P&gt;What would be the most effective way to do this in SAS?. And, if it can be done, could I create more than 3 variables. Is there a max limit ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 20:56:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739078#M230627</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-04T20:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739081#M230628</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;So I am trying this:&lt;/P&gt;&lt;P&gt;Data Want;&lt;/P&gt;&lt;P&gt;Set have;&lt;/P&gt;&lt;P&gt;array w {3} $ 20;&lt;BR /&gt;do i=1 to countw(LONGVAR,';');&lt;BR /&gt;w[i]= scan(LONGVAR,i,';');&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I see the W vars being created but it says my LONGVAR is uninitialized, which is odd because I see the variable in the data set have. Due to this, all of the 3 vars have missing values.&lt;/P&gt;&lt;P&gt;It is also saying&amp;nbsp;&amp;nbsp;"Numeric values have been converted to character values"&lt;/P&gt;&lt;P&gt;Which is odd, since LONGVAR is a string var.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I must be doing something wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 21:04:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739081#M230628</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T21:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739083#M230629</link>
      <description>&lt;P&gt;Thank you. If I have to write this for each string in my data files, I won't be able to do it this way, as I have hundreds of them. Unless, I am misunderstanding.&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;longvar = "I need; to create; 3 short variables"; output;
longvar="Must; create; three short variables"; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 21:07:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739083#M230629</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T21:07:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739084#M230630</link>
      <description>&lt;P&gt;Then maybe start your process at the next step and ensure it refers to the correct input data set that's appropriate for you.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 21:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739084#M230630</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-04T21:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739092#M230632</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;So I am trying this:&lt;/P&gt;
&lt;P&gt;Data Want;&lt;/P&gt;
&lt;P&gt;Set have;&lt;/P&gt;
&lt;P&gt;array w {3} $ 20;&lt;BR /&gt;do i=1 to countw(LONGVAR,';');&lt;BR /&gt;w[i]= scan(LONGVAR,i,';');&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;Run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and I see the W vars being created but it says my LONGVAR is uninitialized, which is odd because I see the variable in the data set have. Due to this, all of the 3 vars have missing values.&lt;/P&gt;
&lt;P&gt;It is also saying&amp;nbsp;&amp;nbsp;"Numeric values have been converted to character values"&lt;/P&gt;
&lt;P&gt;Which is odd, since LONGVAR is a string var.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I must be doing something wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That means you are referencing a variable that doesn't exist in your HAVE data set. So, what is the actual name of the variable that has the long text?&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 22:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739092#M230632</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-04T22:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739093#M230633</link>
      <description>&lt;P&gt;Yes sorry it was a typo in the code. I found it and fixed it.&lt;/P&gt;&lt;P&gt;Now this is the error I am getting for this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;w[i]= scan(LONGVAR,i,';');&lt;/P&gt;&lt;P&gt;Array subscript out of range at line 6526 column 7.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 22:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739093#M230633</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T22:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739097#M230637</link>
      <description>&lt;P&gt;Thank you. Yes, that makes sense &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked really well. Another basic question: How do I make the Col vars permanent variables?&lt;/P&gt;&lt;P&gt;I will need to rename them as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, the wide file does not keep the IDs, it transformed them into obs. I would need to keep the actual ID.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 22:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739097#M230637</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-04T22:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739113#M230644</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes sorry it was a typo in the code. I found it and fixed it.&lt;/P&gt;
&lt;P&gt;Now this is the error I am getting for this line:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;w[i]= scan(LONGVAR,i,';');&lt;/P&gt;
&lt;P&gt;Array subscript out of range at line 6526 column 7.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And just how many ; are in your values. I provide an example for 3 if you do not know how many you actually have then you need a different approach like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; shows, or specify a larger number in the W array to match the maximum number of ; that appear in your variable.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 23:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739113#M230644</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-04T23:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739115#M230645</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/210474"&gt;@Mscarboncopy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you. If I have to write this for each string in my data files, I won't be able to do it this way, as I have hundreds of them. Unless, I am misunderstanding.&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;longvar = "I need; to create; 3 short variables"; output;
longvar="Must; create; three short variables"; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This sort of code, like the example data set I provided, are just to have something to code with. Your data set should already have your varaible with the text in it.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 23:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739115#M230645</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-04T23:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739203#M230686</link>
      <description>&lt;P&gt;Thank you. It was an oversight on my part. The code worked really well. The only thing I need to do now is to use another ID variable in this code (If I use my main ID variables it becomes obs). Thankfully I have 2 ID vars, one that is a string (and I do not need to keep) and the other one is numeric and must keep. I want to use the Id var that is a string in this code. However I am getting&amp;nbsp; " Numeric values have been converted to character values". The N is unchanged and the dat is all&amp;nbsp; there. I tried to transform the string into numeric but my string var for the ids have different widths. Can I ignore the warning? Or should I work on finding a way to convert this string into numeric?&amp;nbsp; Also, how do I make sure that the main ID variable (my numeric one in this case) is showing up in the final Wide data file? Right now, I don't have a subject ID var and I really need that. It only has the obs and the split up string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 12:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739203#M230686</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-05T12:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739211#M230692</link>
      <description>&lt;P&gt;I tried this to see if I could carry all the variables I needed (A B C), including the numericID, but it does not work.&amp;nbsp;Is the solution to this, merging the wide data file back with the main data file? I would then rename the COL variables to make them permanent variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; long (keep= A B C numericID LONGVAR phrase);&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;STRINGid = _n_;&lt;/P&gt;&lt;P&gt;nTerms = count(LONGVAR, ";")+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;do i=&lt;STRONG&gt;1&lt;/STRONG&gt; to nTerms;&lt;/P&gt;&lt;P&gt;phrase = scan(LONGVAR, i, ";");&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;transpose&lt;/STRONG&gt; data=long out=wide;&lt;/P&gt;&lt;P&gt;by STRINGid;&lt;/P&gt;&lt;P&gt;var phrase;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 13:12:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739211#M230692</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-05T13:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739221#M230695</link>
      <description>&lt;P&gt;To keep more variables in the output of PROC TRANSPOSE you can either add them to the BY statement.&lt;/P&gt;
&lt;P&gt;Or use the COPY statement.&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 14:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739221#M230695</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-05T14:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to break up a long character variable into individual (shorter) variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739333#M230736</link>
      <description>&lt;P&gt;Perfect! Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 05 May 2021 20:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-break-up-a-long-character-variable-into-individual/m-p/739333#M230736</guid>
      <dc:creator>Mscarboncopy</dc:creator>
      <dc:date>2021-05-05T20:10:51Z</dc:date>
    </item>
  </channel>
</rss>

