<?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 problem exporting the last variable using FILE statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299258#M60422</link>
    <description>&lt;P&gt;I'm attempting to export a csv file to exactly match the vendor's requirements. Everything &amp;nbsp;is good except the last variable in the data set (sortgroup) does not export. I remember there's something different to do to ensure it gets exported but can't remember.&lt;/P&gt;
&lt;P&gt;Below is the code. I omitted several of the variables below that are being exported for brevity. (all vars are char. I'm running SAS 9.4 64 bit on a PC)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; %let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt; %let _EFIREC_ = 0; /* clear export record count macro variable */&lt;BR /&gt; file 'G:\Departments\Research\TESTING\PSAT\1617\Final.csv' delimiter=',' DSD DROPOVER lrecl=32767;&lt;BR /&gt;set WORK.final end=EFIEOD;&lt;BR /&gt; format aicode $6. ;&lt;BR /&gt; format PSAT8IND $1. ;&lt;BR /&gt; format PSAT10IND $1.;&lt;BR /&gt; .&lt;BR /&gt; .&lt;BR /&gt; format sortgroup $10. ;&lt;BR /&gt; if _n_ = 1 then /* write column names */&lt;BR /&gt;do;&lt;BR /&gt;put&lt;BR /&gt;'AI CODE'&lt;BR /&gt;','&lt;BR /&gt;'PSAT 8/9 TEST ADMINISTRATION INDICATOR'&lt;BR /&gt;','&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;'SAT TEST CENTER'&lt;BR /&gt;','&lt;BR /&gt;'SORT GROUP'&lt;BR /&gt;;&lt;BR /&gt;end;&lt;BR /&gt; do;&lt;BR /&gt; EFIOUT + 1;&lt;BR /&gt; put aicode $ @;&lt;BR /&gt; .&lt;BR /&gt; .&lt;BR /&gt; .&lt;BR /&gt; put testcenter $ @;&lt;BR /&gt; put sortgroup $ ;&lt;BR /&gt; &lt;BR /&gt; ;&lt;BR /&gt; end;&lt;BR /&gt; if _ERROR_ then call symputx('_EFIERR_',1);&lt;BR /&gt; if EFIEOD then call symputx('_EFIREC_',EFIOUT);&lt;BR /&gt; run;&lt;/P&gt;</description>
    <pubDate>Mon, 19 Sep 2016 12:15:52 GMT</pubDate>
    <dc:creator>GreggB</dc:creator>
    <dc:date>2016-09-19T12:15:52Z</dc:date>
    <item>
      <title>problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299258#M60422</link>
      <description>&lt;P&gt;I'm attempting to export a csv file to exactly match the vendor's requirements. Everything &amp;nbsp;is good except the last variable in the data set (sortgroup) does not export. I remember there's something different to do to ensure it gets exported but can't remember.&lt;/P&gt;
&lt;P&gt;Below is the code. I omitted several of the variables below that are being exported for brevity. (all vars are char. I'm running SAS 9.4 64 bit on a PC)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; %let _EFIERR_ = 0; /* set the ERROR detection macro variable */&lt;BR /&gt; %let _EFIREC_ = 0; /* clear export record count macro variable */&lt;BR /&gt; file 'G:\Departments\Research\TESTING\PSAT\1617\Final.csv' delimiter=',' DSD DROPOVER lrecl=32767;&lt;BR /&gt;set WORK.final end=EFIEOD;&lt;BR /&gt; format aicode $6. ;&lt;BR /&gt; format PSAT8IND $1. ;&lt;BR /&gt; format PSAT10IND $1.;&lt;BR /&gt; .&lt;BR /&gt; .&lt;BR /&gt; format sortgroup $10. ;&lt;BR /&gt; if _n_ = 1 then /* write column names */&lt;BR /&gt;do;&lt;BR /&gt;put&lt;BR /&gt;'AI CODE'&lt;BR /&gt;','&lt;BR /&gt;'PSAT 8/9 TEST ADMINISTRATION INDICATOR'&lt;BR /&gt;','&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;.&lt;BR /&gt;'SAT TEST CENTER'&lt;BR /&gt;','&lt;BR /&gt;'SORT GROUP'&lt;BR /&gt;;&lt;BR /&gt;end;&lt;BR /&gt; do;&lt;BR /&gt; EFIOUT + 1;&lt;BR /&gt; put aicode $ @;&lt;BR /&gt; .&lt;BR /&gt; .&lt;BR /&gt; .&lt;BR /&gt; put testcenter $ @;&lt;BR /&gt; put sortgroup $ ;&lt;BR /&gt; &lt;BR /&gt; ;&lt;BR /&gt; end;&lt;BR /&gt; if _ERROR_ then call symputx('_EFIERR_',1);&lt;BR /&gt; if EFIEOD then call symputx('_EFIREC_',EFIOUT);&lt;BR /&gt; run;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 12:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299258#M60422</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2016-09-19T12:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299260#M60423</link>
      <description>&lt;P&gt;Your code looks good on first glance. Are you sure that the number of items in your header line corresponds to the number of variables in the put statements?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd try to reduce the complexity of the data step until I get a correct result, and build back up from there, if no obvious discrepancy can be found in the code.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 12:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299260#M60423</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-19T12:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299262#M60424</link>
      <description>&lt;P&gt;I double checked but I'll check again.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 12:30:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299262#M60424</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2016-09-19T12:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299264#M60425</link>
      <description>&lt;P&gt;Your code looks fine. &amp;nbsp;What is it about the last column that they do not like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that can confuse some programs is if you create the file using PC standard of CR+LF at the end of the line and try to read it on Unix where the standard end of line is just a LF then the CR character can be included into the value of the last column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is the issue than add TERMSTR=LF to your FILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you should not need the FORMAT statements of the $ in the PUT statement.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 12:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299264#M60425</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-19T12:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299266#M60426</link>
      <description>&lt;P&gt;The last column is not exporting at all, just the column header. &amp;nbsp;Unix is not in play here.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 12:39:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299266#M60426</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2016-09-19T12:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299270#M60427</link>
      <description>&lt;P&gt;Also take a good look at the log. If you erroneously tried to export sortgroup, when the variable name is actually sort_group, all you get is a NOTE that sortgroup is uninitialized.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 12:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299270#M60427</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-19T12:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299282#M60429</link>
      <description>&lt;P&gt;So just export the last column and see what is happening.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file 'G:\Departments\Research\TESTING\PSAT\1617\Final.csv' 
    delimiter=',' DSD DROPOVER lrecl=32767
  ;
  if _n_ = 1 then do;
    put 'SORT GROUP' ;
  end;
  set WORK.final ;
  put sortgroup ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also what is with the DROPOVER option on the FILE statement? &amp;nbsp;Is it possible that SORTGROUP is so long that trying to write it would cause the line to be longer than 32,767 characters? &amp;nbsp;If so then try making the LRECL option larger in the FILE statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 13:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299282#M60429</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-09-19T13:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299285#M60430</link>
      <description>&lt;P&gt;So....here was the culprit all along: I had created SORTGROUP by concatenating 2 vars and I didn't trim it. Since SORTGROUP had to be a length of 10, I was actually exporting 10 blanks. Fortunately, it's too early in the day to start drinking.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 13:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299285#M60430</guid>
      <dc:creator>GreggB</dc:creator>
      <dc:date>2016-09-19T13:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: problem exporting the last variable using FILE statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299286#M60431</link>
      <description>&lt;P&gt;Don't be sorry, happens to all of us.&lt;/P&gt;
&lt;P&gt;Still great for us if one of the posts gave you the important hint that led you on to the right trail &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 13:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/problem-exporting-the-last-variable-using-FILE-statement/m-p/299286#M60431</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-09-19T13:47:00Z</dc:date>
    </item>
  </channel>
</rss>

