<?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: Set character variable to 3 blank spaces in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413050#M26558</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/177349"&gt;@alamas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am working in SAS EG and&amp;nbsp;am trying to edit a dataset so that if a character variable is not equal to 'XYZ' then it should be set to '&amp;nbsp; &amp;nbsp;' (which is 3 blank spaces).&amp;nbsp; However when I do this, it is actually set to missing which is ''.&amp;nbsp; Is there a way to set an observation to be a certain amount of blank spaces?&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example code:&lt;/P&gt;
&lt;P&gt;data new;&lt;/P&gt;
&lt;P&gt;set old;&lt;/P&gt;
&lt;P&gt;if AccountCode ^= 'XYZ' then AccountCode = '&amp;nbsp; &amp;nbsp;';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why are you trying to do this?&amp;nbsp;There may be other options that work if we know what you're trying to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Technically if SAS is missing it still has the length of the variable, so it's a length of whatever the variable is, see the LENGTH, LENGTHN/LENGTHC functions. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    length name $15.;
    set sashelp.class;

    if name in ('Alfred', 'Jane') then
        name='   ';
    x1=length(name);
    x2=lengthc(name);
    x3=lengthn(name);
    keep name x1-x3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 13 Nov 2017 20:55:10 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-11-13T20:55:10Z</dc:date>
    <item>
      <title>Set character variable to 3 blank spaces</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413034#M26556</link>
      <description>&lt;P&gt;I am working in SAS EG and&amp;nbsp;am trying to edit a dataset so that if a character variable is not equal to 'XYZ' then it should be set to '&amp;nbsp; &amp;nbsp;' (which is 3 blank spaces).&amp;nbsp; However when I do this, it is actually set to missing which is ''.&amp;nbsp; Is there a way to set an observation to be a certain amount of blank spaces?&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example code:&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;if AccountCode ^= 'XYZ' then AccountCode = '&amp;nbsp; &amp;nbsp;';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 20:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413034#M26556</guid>
      <dc:creator>alamas</dc:creator>
      <dc:date>2017-11-13T20:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Set character variable to 3 blank spaces</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413050#M26558</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/177349"&gt;@alamas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am working in SAS EG and&amp;nbsp;am trying to edit a dataset so that if a character variable is not equal to 'XYZ' then it should be set to '&amp;nbsp; &amp;nbsp;' (which is 3 blank spaces).&amp;nbsp; However when I do this, it is actually set to missing which is ''.&amp;nbsp; Is there a way to set an observation to be a certain amount of blank spaces?&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example code:&lt;/P&gt;
&lt;P&gt;data new;&lt;/P&gt;
&lt;P&gt;set old;&lt;/P&gt;
&lt;P&gt;if AccountCode ^= 'XYZ' then AccountCode = '&amp;nbsp; &amp;nbsp;';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Why are you trying to do this?&amp;nbsp;There may be other options that work if we know what you're trying to do.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Technically if SAS is missing it still has the length of the variable, so it's a length of whatever the variable is, see the LENGTH, LENGTHN/LENGTHC functions. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    length name $15.;
    set sashelp.class;

    if name in ('Alfred', 'Jane') then
        name='   ';
    x1=length(name);
    x2=lengthc(name);
    x3=lengthn(name);
    keep name x1-x3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 20:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413050#M26558</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-13T20:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Set character variable to 3 blank spaces</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413068#M26560</link>
      <description>&lt;P&gt;IF THEN statements do not have the ability to change the length of a character variable.&amp;nbsp; If you are seeing fewer than three blanks, that's because of the tools you are using to view the data.&amp;nbsp; If AccountCode had a length of three originally, it still has a length of 3.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To confirm this, you could try (within a DATA step of course):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;test_string = '*' || AccountCode || '*';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;put test_string;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 21:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413068#M26560</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-13T21:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Set character variable to 3 blank spaces</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413480#M26585</link>
      <description>&lt;P&gt;Thanks for the suggestion.&amp;nbsp; I tried your code but when I set the name = '&amp;nbsp; &amp;nbsp;' then the length(name) of that observation is 1 and the lengthn(name) is 0 rather than 3 for the blank spaces.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 21:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Set-character-variable-to-3-blank-spaces/m-p/413480#M26585</guid>
      <dc:creator>alamas</dc:creator>
      <dc:date>2017-11-14T21:03:59Z</dc:date>
    </item>
  </channel>
</rss>

