<?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 Adding a trailing space to a character variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880579#M347924</link>
    <description>&lt;P&gt;I am trying add a leading and trailing space to a character variable using the following command.&lt;BR /&gt;caps='&amp;nbsp; '||caps;&lt;BR /&gt;caps=caps||'&amp;nbsp;&amp;nbsp;&amp;nbsp; ';&lt;/P&gt;
&lt;P&gt;It is adding a leading space but not the trailing space.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jun 2023 05:48:09 GMT</pubDate>
    <dc:creator>bayzid</dc:creator>
    <dc:date>2023-06-14T05:48:09Z</dc:date>
    <item>
      <title>Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880579#M347924</link>
      <description>&lt;P&gt;I am trying add a leading and trailing space to a character variable using the following command.&lt;BR /&gt;caps='&amp;nbsp; '||caps;&lt;BR /&gt;caps=caps||'&amp;nbsp;&amp;nbsp;&amp;nbsp; ';&lt;/P&gt;
&lt;P&gt;It is adding a leading space but not the trailing space.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 05:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880579#M347924</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-06-14T05:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880582#M347925</link>
      <description>&lt;P&gt;Depending on the defined length (e.g. with a LENGTH statement) and the actual content, the variable will always have trailing blanks; strings in the variable are padded to the defined length with blanks.&lt;/P&gt;
&lt;P&gt;Trailing blanks are usually not displayed, unless you force their display (e.g. by using the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n1oily9h2mwp5cn1dtb5qu8tcj7u.htm" target="_blank" rel="noopener"&gt;$CHAR&lt;/A&gt; format).&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 06:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880582#M347925</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-14T06:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880584#M347927</link>
      <description>&lt;P&gt;I have enough length in the variable. The source variable is 100 Char long and i am using the following&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;caps=put(GenericName,$upcase200.); /*Capitalise all letters and setting the length to 200*/
			caps = compbl(tranwrd(caps, ",", " ,")); /* Adding a space before a comma */
			caps = compbl(tranwrd(caps, ".", " ."));
			caps = compbl(tranwrd(caps, ";", " ;"));
			caps = compbl(tranwrd(caps, "&amp;amp;", " + "));
			*caps = compbl(tranwrd(caps, "/", " + "));
				caps=' '||caps;
				caps=caps||" ";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 06:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880584#M347927</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-06-14T06:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880586#M347928</link>
      <description>&lt;P&gt;So (unless you defined the length elsewhere) your new variable caps will be padded with blanks up to the 200th byte.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 06:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880586#M347928</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-14T06:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880591#M347931</link>
      <description>&lt;P&gt;what is the solution then. I need to add a trailing space for text mining.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 08:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880591#M347931</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-06-14T08:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880592#M347932</link>
      <description>&lt;P&gt;Since there&amp;nbsp;&lt;EM&gt;are&lt;/EM&gt; already trailing spaces, there is no need to add any. The number of trailing spaces is always (defined length of variable) minus (position of last non-blank character).&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 08:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880592#M347932</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-14T08:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880593#M347933</link>
      <description>&lt;P&gt;But my following text mining command is not considering the trailing space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pattern_id=prxparse('/( DONEPEZIL | GALANTAMINE | RIVASTIGMINE | MEMANTINE )/i');
	start=1;
	stop=length(caps);
	call prxnext(pattern_id, start, stop, caps, position, length);
	if (position&amp;gt;0)then
		cm_dementia=substr(caps, position, length);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jun 2023 08:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880593#M347933</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-06-14T08:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880594#M347934</link>
      <description>&lt;P&gt;You don't need the blanks in the pattern IMO. See a similar solution here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Searching-a-string-for-a-list-of-words/td-p/212899" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Searching-a-string-for-a-list-of-words/td-p/212899&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 08:22:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880594#M347934</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-14T08:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880598#M347936</link>
      <description>&lt;P&gt;If &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; indications have not made it clear you can run the code below and analyze the output.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   length var1 $50 var2 $75 var3 $100 var4 $100;
   var1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var2 = "# " || var1;
   len_var2 = length(var2);
   var3 = var2 || " #";
   var4 = substr(var2, 1, len_var2) || " #";
   len_var3 = length(var3);
   len_var4 = length(var4);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jun 2023 09:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880598#M347936</guid>
      <dc:creator>JosvanderVelden</dc:creator>
      <dc:date>2023-06-14T09:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880601#M347938</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Your new variable caps will be padded with blanks up to the 200th byte, ensuring precise and consistent data storage.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 09:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880601#M347938</guid>
      <dc:creator>originalshilaji</dc:creator>
      <dc:date>2023-06-14T09:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880635#M347959</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108705"&gt;@bayzid&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But my following text mining command is not considering the trailing space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pattern_id=prxparse('/( DONEPEZIL | GALANTAMINE | RIVASTIGMINE | MEMANTINE )/i');
	start=1;
	stop=length(caps);
	call prxnext(pattern_id, start, stop, caps, position, length);
	if (position&amp;gt;0)then
		cm_dementia=substr(caps, position, length);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I assume it is not matching because you told PRXNEXT()&amp;nbsp;&lt;STRONG&gt;to NOT use any of the trailing spaces&lt;/STRONG&gt; by setting STOP to the last non-space character in the variable.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 12:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880635#M347959</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-14T12:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880640#M347961</link>
      <description>&lt;P&gt;Everything is working when I am adding a dot at the end of the space.&lt;BR /&gt;caps1=' '||caps1;&lt;BR /&gt;caps=caps1||" .";&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 12:36:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880640#M347961</guid>
      <dc:creator>bayzid</dc:creator>
      <dc:date>2023-06-14T12:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880868#M348053</link>
      <description>&lt;P&gt;I think you should drop the leading and trailing blanks, and look for word boundaries instead - beginning of string or end of string is also a word boundary:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pattern_id=prxparse('/\b(DONEPEZIL|GALANTAMINE|RIVASTIGMINE|MEMANTINE)\b/i');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2023 07:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/880868#M348053</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-06-15T07:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/881019#M348131</link>
      <description>&lt;P&gt;That will pick the keyword by itself or with another keywords. For example, "DONEPEZIL" and "DONEPEZIL/OTHER". But i do not want the "DONEPEZIL/OTHER" to be picked up.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 21:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/881019#M348131</guid>
      <dc:creator>BayzidurRahman</dc:creator>
      <dc:date>2023-06-15T21:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/881031#M348139</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/437116"&gt;@BayzidurRahman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That will pick the keyword by itself or with another keywords. For example, "DONEPEZIL" and "DONEPEZIL/OTHER". But i do not want the "DONEPEZIL/OTHER" to be picked up.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do not add the spaces to the VARIABLE.&amp;nbsp; Add them to the string you pass to the FUNCTION. Remember that means that the position that it found the start of the match is off by one because of the extra space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;pattern_id=prxparse('/ (DONEPEZIL|GALANTAMINE|RIVASTIGMINE|MEMANTINE) /i');

call prxnext(pattern_id, start, vlength(caps)+2 , ' '||caps||' ', position, length);
if (position&amp;gt;0) then cm_dementia=substr(caps, position-1, length);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Jun 2023 23:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/881031#M348139</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-15T23:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a trailing space to a character variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/881040#M348142</link>
      <description>&lt;P&gt;It could also be done with a RegEx but in your case may-be just use the scan() function with a blank defined as the word delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  infile datalines truncover;
  input str $100.;
  length cm_dementia $40;
  do _i=1 to countw(str,' ');
    cm_dementia=scan(str,_i,' ');
    if upcase(cm_dementia) in ('DONEPEZIL', 'GALANTAMINE', 'RIVASTIGMINE', 'MEMANTINE') then
    output;
  end;
datalines;
donepezil galantamine donepezil/other rivastigmine memantine
;
proc print data=demo;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1686890339267.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/85043i36F6D22391610A53/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1686890339267.png" alt="Patrick_0-1686890339267.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 04:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-trailing-space-to-a-character-variable/m-p/881040#M348142</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-06-16T04:39:14Z</dc:date>
    </item>
  </channel>
</rss>

