<?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: change text into variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873861#M345248</link>
    <description>&lt;P&gt;Correct, I would. It's okay if you're not happy with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 04 May 2023 13:30:33 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2023-05-04T13:30:33Z</dc:date>
    <item>
      <title>change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873615#M345186</link>
      <description>&lt;P&gt;could you help me to cut this strings and make variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;string= "The project was in development for approximately three years at&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;, during which time a&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;that differed significantly from the novel was written.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;acquired the rights to the novel after the project's&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;wrote a new adaptation of the novel shortly before the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;and sought to be faithful to the novel's storyline.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;March 2008 and took 44 days&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;completed on May 2;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;the film was shot in the states of&amp;nbsp;"&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 12:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873615#M345186</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-05-03T12:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873628#M345191</link>
      <description>&lt;P&gt;Cut the string based upon what criteria?&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 13:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873628#M345191</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-03T13:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873630#M345193</link>
      <description>&lt;P&gt;maximum 200 length, should not cut the word from the middle&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 13:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873630#M345193</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-05-03T13:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873634#M345195</link>
      <description>&lt;P&gt;need to use doo loop&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 13:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873634#M345195</guid>
      <dc:creator>kindbe17</dc:creator>
      <dc:date>2023-05-03T13:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873640#M345198</link>
      <description>&lt;P&gt;Certainly. May I suggest that from now on these important details be included in your original post, along with any other important details not already mentioned.&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 13:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873640#M345198</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-03T13:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873645#M345200</link>
      <description>&lt;P&gt;It's not what I use in a professional environment but might give you an idea of the possibilites:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
   string= "The project was in development for approximately three years at , during which time a that differed significantly from the novel was written.  acquired the rights to the novel after the project's  wrote a new adaptation of the novel shortly before the and sought to be faithful to the novel's storyline.  March 2008 and took 44 days completed on May 2; the film was shot in the states of ";
RUN;

%MACRO split(varName=,varCount=,varLength=);
   %local code;
   %do i=1 %to &amp;amp;varCount.;
      %if &amp;amp;i. eq &amp;amp;varCount. %then %let &amp;amp;&amp;amp;varName.&amp;amp;i.=%nrbquote(length &amp;amp;&amp;amp;varName.&amp;amp;i. $&amp;amp;varLength.%str(;) &amp;amp;&amp;amp;varName.&amp;amp;i.=substr(&amp;amp;varName.,%eval((&amp;amp;i.-1)*&amp;amp;varLength.+1))%str(;));
      %else %if &amp;amp;i. eq 1 %then %let &amp;amp;&amp;amp;varName.&amp;amp;i.=%nrbquote(length &amp;amp;&amp;amp;varName.&amp;amp;i. $&amp;amp;varLength.%str(;) &amp;amp;&amp;amp;varName.&amp;amp;i.=substr(&amp;amp;varName.,1,&amp;amp;varLength.)%str(;));
      %else %let &amp;amp;&amp;amp;varName.&amp;amp;i.=%nrbquote(length &amp;amp;&amp;amp;varName.&amp;amp;i. $&amp;amp;varLength.%str(;) &amp;amp;&amp;amp;varName.&amp;amp;i.=substr(&amp;amp;varName.,%eval((&amp;amp;i.-1)*&amp;amp;varLength.+1),&amp;amp;varLength.)%str(;));

      %let code=&amp;amp;code. &amp;amp;&amp;amp;&amp;amp;varName.&amp;amp;i.;
   %end;
   &amp;amp;code.
%MEND split;

DATA _NULL_;
   SET have;
   xvarLength=200;
   xvarCount=ceil(lengthn(string)/xvarLength);
   call execute('DATA want;set &amp;amp;syslast.; %nrstr(%split(varName=string,varCount='||strip(put(xvarCount,best.))||',varLength='||strip(put(xvarLength,best.))||');); run;');
   drop xvarLength xvarCount;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 May 2023 14:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873645#M345200</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-03T14:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873656#M345201</link>
      <description>&lt;P&gt;Why would you use macro code to deal with data that is an actual variable?&lt;/P&gt;
&lt;P&gt;Just define the variables and then loop over the words in the string and decide whether or not you can add the new word to the current short string or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's split the string into variables of length 50 just to demonstrate the concept.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length string $400;
  string= "The project was in development for approximately three years at , "
       || "during which time a that differed significantly from the novel was written."
       || "  acquired the rights to the novel after the project's  wrote a new"
       || " adaptation of the novel shortly before the and sought to be faithful"
       || " to the novel's storyline.  March 2008 and took 44 days completed"
       || " on May 2; the film was shot in the states of "
  ;
run;

data want;
  set have;
  length varnum wordnum 8 word $50 ;
  array short [10] $50 ;
  varnum=1;
  do wordnum=1 to countw(string,' ');
    word=scan(string,wordnum,' ');
    if 50 &amp;lt; length(catx(' ',short[varnum],word)) then varnum+1;
    short[varnum]=catx(' ',short[varnum],word);
  end;
  drop varnum wordnum word;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1683125531751.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83551i310DFB09CC173EC4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1683125531751.png" alt="Tom_0-1683125531751.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 May 2023 14:55:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873656#M345201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-03T14:55:34Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873672#M345203</link>
      <description>&lt;P&gt;Let's say you have a text file (c:\temp\t.txt in the code below), with the maximum length of each line of 1,000 characters.&amp;nbsp; Then you could:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  infile 'c:\temp\t.txt' truncover;
  input _line_of_text $1000. ;
  array _str {5} $200 str1-str5 ;
  do _s=1 to dim(_str) while (_line_of_text^= ' ');
    do _c=201 to 1 by -1 until (char(_line_of_text,_c)=' ');
    end;
    _str{_s}=substr(_line_of_text,1,_c);
    _line_of_text=left(substr(_line_of_text,_c));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 May 2023 15:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873672#M345203</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-05-03T15:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873789#M345224</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; because if you've ever coded SDTMs you wouldn't repeat your code in each of your datasteps, would you?&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 05:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873789#M345224</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-04T05:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873859#M345247</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77163"&gt;@Oligolas&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; because if you've ever coded SDTMs you wouldn't repeat your code in each of your datasteps, would you?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not sure what you point is there.&amp;nbsp; It sounds like you are making the case for creating a SAS macro.&amp;nbsp; But if you did create a macro you would still write the macro to generate SAS code to manipulate the data.&amp;nbsp; Not try to manipulate the data using SAS MACRO statements.&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 13:19:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873859#M345247</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-04T13:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: change text into variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873861#M345248</link>
      <description>&lt;P&gt;Correct, I would. It's okay if you're not happy with it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 May 2023 13:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-text-into-variables/m-p/873861#M345248</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2023-05-04T13:30:33Z</dc:date>
    </item>
  </channel>
</rss>

