<?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: Leading Space in SAS data set in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727705#M38366</link>
    <description>&lt;P&gt;How do you know it "didn't work"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By default most of the procedures creating output will not display a leading space.&lt;/P&gt;
&lt;P&gt;And on potential issue is that depending on the assigned length of a variable if you attempt to add a leading space the result might not fit in allowed space for that defined variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this code;&lt;/P&gt;
&lt;PRE&gt;data example;
   x='Jack';
   y=' '||x;
   z=cat(' ',x);
   ly=length(y);
   lz=length(z);
run;
/* look at defined length for x in the output*/
proc contents data=example;
run;

data example2;
   set example ;
   /* attempt to insert space in existing variable*/
   x=' '||x;
run;&lt;/PRE&gt;
&lt;P&gt;If you print the Example data set you will see that the value for x is "Jack".&amp;nbsp; In the second set print will only show "Jac" but opening the set in the table viewer you may be able to tell that there is a space and the K is no longer there because the "space" makes the value too long to fit in the 4 spaces. &lt;/P&gt;</description>
    <pubDate>Fri, 19 Mar 2021 09:15:12 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-03-19T09:15:12Z</dc:date>
    <item>
      <title>Trailing Space in SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727695#M38365</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I have a data set with 1 variable and 3 inputs which is as follow:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;VarName&lt;/P&gt;&lt;P&gt;1) Jack&lt;/P&gt;&lt;P&gt;2) Alfred Crooks&lt;/P&gt;&lt;P&gt;3) Julia&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to store "Jack" as "Jack&amp;nbsp; " (One trailing space in the end) and rest of the inputs to remain as it is in sas data set. can this be done in SAS ? I have tried different function tranwrd, cat, || , also through if else condition but nothing worked. It would be great if anyone can guide me on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 12:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727695#M38365</guid>
      <dc:creator>karan96</dc:creator>
      <dc:date>2021-03-19T12:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Space in SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727705#M38366</link>
      <description>&lt;P&gt;How do you know it "didn't work"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By default most of the procedures creating output will not display a leading space.&lt;/P&gt;
&lt;P&gt;And on potential issue is that depending on the assigned length of a variable if you attempt to add a leading space the result might not fit in allowed space for that defined variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this code;&lt;/P&gt;
&lt;PRE&gt;data example;
   x='Jack';
   y=' '||x;
   z=cat(' ',x);
   ly=length(y);
   lz=length(z);
run;
/* look at defined length for x in the output*/
proc contents data=example;
run;

data example2;
   set example ;
   /* attempt to insert space in existing variable*/
   x=' '||x;
run;&lt;/PRE&gt;
&lt;P&gt;If you print the Example data set you will see that the value for x is "Jack".&amp;nbsp; In the second set print will only show "Jac" but opening the set in the table viewer you may be able to tell that there is a space and the K is no longer there because the "space" makes the value too long to fit in the 4 spaces. &lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 09:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727705#M38366</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-19T09:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Leading Space in SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727724#M38367</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276777"&gt;@karan96&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276777"&gt;@karan96&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to store "Jack" as "Jack&amp;nbsp; " (One leading space in the end)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What you describe is rather a &lt;EM&gt;trailing&lt;/EM&gt; blank. If your character variable needs to accommodate a value like "&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;Alfred Crooks&lt;/FONT&gt;" it must have a length of at least 13. Then an observation containing the name "&lt;FONT face="courier new,courier"&gt;Jack&lt;/FONT&gt;" will actually contain the string "&lt;FONT face="courier new,courier"&gt;Jack&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/FONT&gt;" with at least&amp;nbsp;&lt;EM&gt;9&lt;/EM&gt; (=13-4) trailing blanks -- assuming a &lt;EM&gt;traditional&lt;/EM&gt; (fixed-width) character variable, not the newer VARCHAR data type.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note that trailing blanks are ignored in character comparisons, e.g., the condition &lt;FONT face="courier new,courier"&gt;"Jack" = "Jack&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"&lt;/FONT&gt; is true. But in other situations like concatenating character values (e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;name=firstname||lastname&amp;nbsp;&lt;/FONT&gt;[&lt;EM&gt;not recommended&lt;/EM&gt;]) or using certain character functions the trailing blanks must not be forgotten.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Mar 2021 10:50:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727724#M38367</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-03-19T10:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trailing Space in SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727736#M38368</link>
      <description>&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;SAS has two variable types. Floating point numbers and fixed length character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To distinguish 'Jack ' from 'Jack' you will need to store extra information somehow.&amp;nbsp; Either include something in the variable itself, like quotes or a delimiter or stop character.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input string $40.;
cards;
"Jack "
Alfred Crooks
Julia
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or store the desired length in a separate variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input length string $40.;
cards;
5  Jack 
13 Alfred Crooks
5  Julia
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Mar 2021 12:26:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/727736#M38368</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-19T12:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trailing Space in SAS data set</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/728021#M38377</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/276777"&gt;@karan96&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;You can have a trailing space but with single quote. Thus for Jack it will be 'Jack ' but not "Jack ".&lt;BR /&gt;The output will be like this. There is a trailing space at the end of each variable.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1616355705016.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56206i55AC8B823BE35680/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1616355705016.png" alt="Sajid01_0-1616355705016.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The code is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input Name  $40.;
datalines;
Jack
Alfred Crooks
Julia
;
run;

data test;
set test;
Name2="'"||strip(name)||" '";
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Mar 2021 19:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Trailing-Space-in-SAS-data-set/m-p/728021#M38377</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-03-21T19:44:45Z</dc:date>
    </item>
  </channel>
</rss>

