<?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 SAS Dropping Trailing Spaces in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644319#M192445</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am using SAS to output a file where the first line is a header that requires a set of 32 trailing spaces (weird client requirement).&lt;/P&gt;&lt;P&gt;Unfortunately everything I try has SAS dropping the extra spaces when I am writing to the Excel file. I know the method I'm doing to create the header line is not the most elegant, but if I could get the trailing spaces to remain I'd be grateful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the purposes of the below example, the v_RCount is 144.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Turning previous dataset into single column concat*/&lt;/P&gt;&lt;P&gt;Proc SQL noprint;&lt;BR /&gt;Create Table Output as&lt;BR /&gt;Select&lt;BR /&gt;Record_ID || Medicaid_ID || Fill_date || NDC || Rx_No || Billing_Provider_ID || Phys_Provider_ID || CLAIM_INDICATOR as Results&lt;BR /&gt;from SQL_Table;&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Getting count of obs for header and creating header*/&lt;/P&gt;&lt;P&gt;Data Header;&lt;BR /&gt;call symputx('v_RCount',v_RCount);&lt;BR /&gt;format head $char75.;&lt;BR /&gt;set output end=eof nobs=v_RCount;&lt;BR /&gt;output;&lt;BR /&gt;if eof then&lt;BR /&gt;do;&lt;BR /&gt;head=cat("HNCPDP340BMB000734ORDHS",put(date(),yymmddn8.),put(v_RCount,z12.),"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;drop results;&lt;BR /&gt;rename head=Results;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Exporting file as excel file*/&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set Header&lt;BR /&gt;Output;&lt;BR /&gt;if Results = "" then delete;&lt;BR /&gt;file "&amp;amp;v_Path&amp;amp;v_Fname";&lt;BR /&gt;put Results;&lt;BR /&gt;Run;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Apr 2020 18:05:05 GMT</pubDate>
    <dc:creator>ACoyle</dc:creator>
    <dc:date>2020-04-30T18:05:05Z</dc:date>
    <item>
      <title>SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644319#M192445</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am using SAS to output a file where the first line is a header that requires a set of 32 trailing spaces (weird client requirement).&lt;/P&gt;&lt;P&gt;Unfortunately everything I try has SAS dropping the extra spaces when I am writing to the Excel file. I know the method I'm doing to create the header line is not the most elegant, but if I could get the trailing spaces to remain I'd be grateful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the purposes of the below example, the v_RCount is 144.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Turning previous dataset into single column concat*/&lt;/P&gt;&lt;P&gt;Proc SQL noprint;&lt;BR /&gt;Create Table Output as&lt;BR /&gt;Select&lt;BR /&gt;Record_ID || Medicaid_ID || Fill_date || NDC || Rx_No || Billing_Provider_ID || Phys_Provider_ID || CLAIM_INDICATOR as Results&lt;BR /&gt;from SQL_Table;&lt;BR /&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Getting count of obs for header and creating header*/&lt;/P&gt;&lt;P&gt;Data Header;&lt;BR /&gt;call symputx('v_RCount',v_RCount);&lt;BR /&gt;format head $char75.;&lt;BR /&gt;set output end=eof nobs=v_RCount;&lt;BR /&gt;output;&lt;BR /&gt;if eof then&lt;BR /&gt;do;&lt;BR /&gt;head=cat("HNCPDP340BMB000734ORDHS",put(date(),yymmddn8.),put(v_RCount,z12.),"&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ");&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;drop results;&lt;BR /&gt;rename head=Results;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Exporting file as excel file*/&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set Header&lt;BR /&gt;Output;&lt;BR /&gt;if Results = "" then delete;&lt;BR /&gt;file "&amp;amp;v_Path&amp;amp;v_Fname";&lt;BR /&gt;put Results;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 18:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644319#M192445</guid>
      <dc:creator>ACoyle</dc:creator>
      <dc:date>2020-04-30T18:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644373#M192454</link>
      <description>&lt;P&gt;Have you checked the file in the editor, not in Excel?&lt;/P&gt;
&lt;P&gt;How does excel enter this process when you're creating a file with spaces that's usually a text file not an excel file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds like they want a fixed width file exported.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 19:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644373#M192454</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-30T19:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644374#M192455</link>
      <description>&lt;P&gt;Sorry, yes this is a fixed width text file being exported (not sure what I was thinking when I wrote excel). And to your question, yes I have checked it in a different editor (slickedit) and the spaces are not present.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 19:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644374#M192455</guid>
      <dc:creator>ACoyle</dc:creator>
      <dc:date>2020-04-30T19:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644375#M192456</link>
      <description>Make sure to specify LRECL on the FILE statement to specify the length of the full record.</description>
      <pubDate>Thu, 30 Apr 2020 19:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644375#M192456</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-04-30T19:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644386#M192458</link>
      <description>&lt;P&gt;I've added the lrecl section as suggested, but am still missing the trailing spaces in the header.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set Header&lt;BR /&gt;Output;&lt;BR /&gt;if Results = "" then delete;&lt;BR /&gt;file "&amp;amp;v_Path&amp;amp;v_Fname" lrecl=75;&lt;BR /&gt;put Results;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 20:25:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644386#M192458</guid>
      <dc:creator>ACoyle</dc:creator>
      <dc:date>2020-04-30T20:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644387#M192459</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305133"&gt;@ACoyle&lt;/a&gt;: Add the &lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n15o12lpyoe4gfn1y1vcp6xs6966.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n0bx4nd80sk4z0n1qfdz0c2mrpbt" target="_blank" rel="noopener"&gt;PAD option&lt;/A&gt;&amp;nbsp;to the FILE statement.&lt;/P&gt;
&lt;PRE&gt;file "&amp;amp;v_Path&amp;amp;v_Fname" lrecl=75 &lt;FONT color="#00CCFF"&gt;&lt;STRONG&gt;pad&lt;/STRONG&gt;&lt;/FONT&gt;;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Apr 2020 20:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644387#M192459</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-30T20:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644389#M192460</link>
      <description>&lt;P&gt;Thank you so much for the fast reply and help with this! As usual, there are so many options available in SAS that I missed the very one I needed.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Apr 2020 20:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644389#M192460</guid>
      <dc:creator>ACoyle</dc:creator>
      <dc:date>2020-04-30T20:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644466#M192492</link>
      <description>&lt;P&gt;You're overcomplicating things by a mile here. This can be solved very simple:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.class nobs=nobs;
file '/folders/myfolders/test.txt' dlm='|' dsd;
if _n_ = 1
then do;
  length header $75;
  header = cat("HNCPDP340BMB000734ORDHS",put(date(),yymmddn8.),put(nobs,z12.));
  put header $char75.;
end;
put name sex age weight height;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The log already tells us that the line was correctly padded:&lt;/P&gt;
&lt;PRE&gt;73         data _null_;
 74         set sashelp.class nobs=nobs;
 75         file '/folders/myfolders/test.txt' dlm='|' dsd;
 76         if _n_ = 1
 77         then do;
 78           length header $75;
 79           header = cat("HNCPDP340BMB000734ORDHS",put(date(),yymmddn8.),put(nobs,z12.));
 80           put header $char75.;
 81         end;
 82         put name sex age weight height;
 83         run;
 
 NOTE: The file '/folders/myfolders/test.txt' is:
       Dateiname=/folders/myfolders/test.txt,
       Besitzername=root,Gruppenname=vboxsf,
       Zugriffsberechtigung=-rwxrwx---,
       Zuletzt geändert=01. Mai 2020 09.34 Uhr
 
 NOTE: 20 records were written to the file '/folders/myfolders/test.txt'.
       The minimum record length was 17.
       The maximum record length was 75.
 NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.02 seconds
       cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;and this is the resulting file:&lt;/P&gt;
&lt;PRE&gt;HNCPDP340BMB000734ORDHS20200501000000000019                                
Alfred|M|14|112.5|69
Alice|F|13|84|56.5
Barbara|F|13|98|65.3
Carol|F|14|102.5|62.8
Henry|M|14|102.5|63.5
James|M|12|83|57.3
Jane|F|12|84.5|59.8
Janet|F|15|112.5|62.5
Jeffrey|M|13|84|62.5
John|M|12|99.5|59
Joyce|F|11|50.5|51.3
Judy|F|14|90|64.3
Louise|F|12|77|56.3
Mary|F|15|112|66.5
Philip|M|16|150|72
Robert|M|12|128|64.8
Ronald|M|15|133|67
Thomas|M|11|85|57.5
William|M|15|112|66.5
&lt;/PRE&gt;
&lt;P&gt;when you move the cursor over the text, you'll see the blanks.&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 07:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644466#M192492</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-01T07:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Dropping Trailing Spaces</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644471#M192497</link>
      <description>&lt;P&gt;This is interesting! Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, for pointing this out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Literally for decades, we've been taught: "&lt;SPAN&gt;The $CHAR&lt;/SPAN&gt;&lt;EM&gt;&lt;SPAN class="userSuppliedValue"&gt;w&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN&gt;. format is identical to the $&lt;/SPAN&gt;&lt;SPAN class="userSuppliedValue"&gt;&lt;EM&gt;w&lt;/EM&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;format." (&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/63324/HTML/default/viewer.htm#n1oily9h2mwp5cn1dtb5qu8tcj7u.htm" target="_blank" rel="noopener"&gt;SAS® 9.3 Formats and Informats: Reference&lt;/A&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; Now, all of a sudden, it says: "The $CHAR&lt;EM class="xisDoc-userSuppliedValue"&gt;w&lt;/EM&gt;. format is not identical to the $&lt;EM class="xisDoc-userSuppliedValue"&gt;w&lt;/EM&gt;. format. The $CHAR&lt;EM class="xisDoc-userSuppliedValue"&gt;w&lt;/EM&gt;. format does not trim trailing blanks. The $&lt;EM class="xisDoc-userSuppliedValue"&gt;w&lt;/EM&gt;. format trims trailing blanks." (&lt;A href="https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=n1oily9h2mwp5cn1dtb5qu8tcj7u.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS® 9.4 Formats and Informats: Reference&lt;/A&gt;).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And what does "&lt;A href="https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=leforinforrefwhatsnew94.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;What's New in SAS 9.4 Formats and Informats&lt;/A&gt;" say about this unexpected change: nothing!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Moreover, both the DS2 and FedSQL flavors of the $CHAR&lt;EM&gt;w&lt;/EM&gt;. format are still documented as being "identical" to the corresponding $&lt;EM&gt;w&lt;/EM&gt;. formats (in &lt;A href="https://documentation.sas.com/?docsetId=ds2ref&amp;amp;docsetTarget=n0f58rw9dkbmgen1sagzaj1uhhi5.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS® 9.4 DS2 Language Reference&lt;/A&gt; and&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=fedsqlref&amp;amp;docsetTarget=n1esdgtqxeb2pqn1sjdxew4cnqca.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;SAS® 9.4 FedSQL Language Reference&lt;/A&gt;).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 May 2020 09:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Dropping-Trailing-Spaces/m-p/644471#M192497</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-05-01T09:10:24Z</dc:date>
    </item>
  </channel>
</rss>

