<?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: Keeping Trailing spaces in SAS dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29042#M5450</link>
    <description>&amp;gt; figure&lt;BR /&gt;
&amp;gt; out a way to enclose your data values in&lt;BR /&gt;
&amp;gt; quotation-marks.  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&lt;BR /&gt;
Hi thanks for your suggestion.  I think if I enclose it in quotation marks, it might work.&lt;BR /&gt;
&lt;BR /&gt;
So I'll have SAS reading in&lt;BR /&gt;
&lt;BR /&gt;
: 3 4 Hi     to &lt;BR /&gt;
: 3 4 "Hi "&lt;BR /&gt;
&lt;BR /&gt;
How do I tell SAS to read in everything between the quotation " marks in the input step?&lt;BR /&gt;
&lt;BR /&gt;
Because I have to set the delimiter to a space ' ' I'm afriad SAS will input in&lt;BR /&gt;
&lt;BR /&gt;
"Hi  and  " into different fields because it still thinks the space is the delimiter</description>
    <pubDate>Fri, 11 Dec 2009 02:06:34 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-12-11T02:06:34Z</dc:date>
    <item>
      <title>Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29040#M5448</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
I read in a text file eg.&lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;filename indat 'C:\songs.txt';&lt;BR /&gt;
infile indat delimiter=' ' missover length=reclen;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
the format of the file is similar to&lt;BR /&gt;
&lt;BR /&gt;
:3 4 Hi &lt;BR /&gt;
:7 4 How &lt;BR /&gt;
&lt;BR /&gt;
so the format is a ':', followed by a delimiter space ' ', followed by a numeric, delimiter space ' ', followed by a numeric, delimiter space ' ', followed by a character&lt;BR /&gt;
&lt;BR /&gt;
However after the character there is often a trailing space ' ' which is not a delimiter but a part of what I would like to read into the SAS dataset.  This ' ' always gets missed by the SAS input statement.  How do I import this trailing space.</description>
      <pubDate>Thu, 10 Dec 2009 23:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29040#M5448</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-10T23:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29041#M5449</link>
      <description>Hmm - you say you have a delimiter character (a blank-space) that is also part of a data-field, but only sometimes?  Might there be more than 1, possibly 2 or more?  Suggest you re-define the delimiter character as something other than your data or figure out a way to enclose your data values in quotation-marks.  &lt;BR /&gt;
&lt;BR /&gt;
But, still, what you are looking for is that SAS carry forward any imbedded (extra) blank in your character variable(s).  SAS variables have a declared (or implied) LENGTH attribute and so you will have the padded-blanks stored as part of the variable -- but I suppose the question is to ask: what do you expect to do with those trailing blank characters?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 11 Dec 2009 01:10:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29041#M5449</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-11T01:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29042#M5450</link>
      <description>&amp;gt; figure&lt;BR /&gt;
&amp;gt; out a way to enclose your data values in&lt;BR /&gt;
&amp;gt; quotation-marks.  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&lt;BR /&gt;
Hi thanks for your suggestion.  I think if I enclose it in quotation marks, it might work.&lt;BR /&gt;
&lt;BR /&gt;
So I'll have SAS reading in&lt;BR /&gt;
&lt;BR /&gt;
: 3 4 Hi     to &lt;BR /&gt;
: 3 4 "Hi "&lt;BR /&gt;
&lt;BR /&gt;
How do I tell SAS to read in everything between the quotation " marks in the input step?&lt;BR /&gt;
&lt;BR /&gt;
Because I have to set the delimiter to a space ' ' I'm afriad SAS will input in&lt;BR /&gt;
&lt;BR /&gt;
"Hi  and  " into different fields because it still thinks the space is the delimiter</description>
      <pubDate>Fri, 11 Dec 2009 02:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29042#M5450</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-11T02:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29043#M5451</link>
      <description>Take advantage of the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website either using its SEARCH facility or consider using a Google advanced search such as the one below:&lt;BR /&gt;
&lt;BR /&gt;
infile reading delimited files quotation marks site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 11 Dec 2009 04:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29043#M5451</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-11T04:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29044#M5452</link>
      <description>You can use QUOTE informat in order to read the Vaue which has enclosed by quotes.</description>
      <pubDate>Wed, 16 Dec 2009 18:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29044#M5452</guid>
      <dc:creator>DPraba79</dc:creator>
      <dc:date>2009-12-16T18:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29045#M5453</link>
      <description>Reading the data is not the real challenge - the OP wants to have SAS character variables retain any trailing spaces up to the declared SAS LENGTH definition (or the SAS default-assigned).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 16 Dec 2009 19:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29045#M5453</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-16T19:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping Trailing spaces in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29046#M5454</link>
      <description>There is another issue in regard to trailing blanks. When you read in the data, you might work hard to read in the trailing blanks. However, consider this data:&lt;BR /&gt;
[pre]&lt;BR /&gt;
data muppets;&lt;BR /&gt;
  length On_show $15 Muppet $20;&lt;BR /&gt;
  infile datalines dsd dlm=',';&lt;BR /&gt;
  input On_show $ Muppet $ numtrail;&lt;BR /&gt;
  calclength = length(Muppet);&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
"Sesame Street","Kermit   ",3&lt;BR /&gt;
"Muppet Show","Miss Piggy ",1&lt;BR /&gt;
"Sesame Street","Snuffleupagus  ",2&lt;BR /&gt;
"Muppet Show","Gonzo   ",3&lt;BR /&gt;
"Fraggle Rock","Gobo Fraggle    ",4&lt;BR /&gt;
"Fraggle Rock","Uncle Traveling Matt",0&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
               &lt;BR /&gt;
It's all very well to have trailing blanks explicitly included when the variable is read in. However, the LENGTH of the MUPPET variable will be $20. So it doesn't matter if Kermit has 3 trailing spaces or Miss Piggy has 1 trailing space -- they are individual variable VALUES, which will be internally stored with a maximum length of 20 characters.&lt;BR /&gt;
      &lt;BR /&gt;
If we use the LENGTH function to determine the number of characters in any given value for MUPPET, the LENGTH function -excludes-  any trailing blanks and you see that the calculated length (if you run the program) shows only 6 as the length for what was read as "Kermit   " (with 3 trailing blanks) and shows 10 as the length for what was read as "Miss Piggy " (with 1 trailing blank).&lt;BR /&gt;
  &lt;BR /&gt;
This is the output you get when you do a PROC PRINT of the data being read above:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   Variable and Calculated Length -- "trailing blanks" are ignored&lt;BR /&gt;
             &lt;BR /&gt;
 Obs      On_show      Muppet                 calclength   numtrail&lt;BR /&gt;
                         &lt;BR /&gt;
  1    Sesame Street   Kermit                      6           3&lt;BR /&gt;
  2    Muppet Show     Miss Piggy                 10           1&lt;BR /&gt;
  3    Sesame Street   Snuffleupagus              13           2&lt;BR /&gt;
  4    Muppet Show     Gonzo                       5           3&lt;BR /&gt;
  5    Fraggle Rock    Gobo Fraggle               12           4&lt;BR /&gt;
  6    Fraggle Rock    Uncle Traveling Matt       20           0&lt;BR /&gt;
                             &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                   &lt;BR /&gt;
And, if you look at the variable characteristics with PROC SQL, you see that the length of the variable is the maximum, or $20:&lt;BR /&gt;
[pre]&lt;BR /&gt;
      Length as stored in the descriptor portion of the dataset&lt;BR /&gt;
                                     &lt;BR /&gt;
                                           Column    Column&lt;BR /&gt;
         Column Name                       Type      Length&lt;BR /&gt;
         --------------------------------------------------------------------------&lt;BR /&gt;
         On_show                           char          15&lt;BR /&gt;
         Muppet                            char          20&lt;BR /&gt;
         numtrail                          num            8&lt;BR /&gt;
         calclength                        num            8&lt;BR /&gt;
                                           &lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                                                         &lt;BR /&gt;
Since I don't understand WHY the trailing blanks are significant, and since I do understand how SAS deals with the LENGTH of character variables, I find myself wondering whether this is a moot question or some kind of important distinction for some other software, but a distinction which, in the end, doesn't really matter in SAS.       &lt;BR /&gt;
                                                                      &lt;BR /&gt;
cynthia</description>
      <pubDate>Wed, 16 Dec 2009 21:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-Trailing-spaces-in-SAS-dataset/m-p/29046#M5454</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-12-16T21:25:19Z</dc:date>
    </item>
  </channel>
</rss>

