<?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 How to add header text in first two columns of row 1 in a csv proc export in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/687956#M79594</link>
    <description>&lt;P&gt;Background: I'm preparing multiple data submissions and the upload requirements include two things: 1) data must be in a csv format and 2) the first row must include the form name and version number. Essentially, when viewing data from a spreadsheet, form name must be in cell A1 and version number needs to be in cell B1. The variable names are located in row 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no difficulty with exporting the data as a csv. I'm seeking help with programming the form name and version number into the first row and first two columns of the csv. I've been adding the information manually but it's getting tiresome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mmm7_0-1601493486065.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49976i6D825AF725FCA1A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mmm7_0-1601493486065.png" alt="mmm7_0-1601493486065.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 19:24:17 GMT</pubDate>
    <dc:creator>mmm7</dc:creator>
    <dc:date>2020-09-30T19:24:17Z</dc:date>
    <item>
      <title>How to add header text in first two columns of row 1 in a csv proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/687956#M79594</link>
      <description>&lt;P&gt;Background: I'm preparing multiple data submissions and the upload requirements include two things: 1) data must be in a csv format and 2) the first row must include the form name and version number. Essentially, when viewing data from a spreadsheet, form name must be in cell A1 and version number needs to be in cell B1. The variable names are located in row 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have no difficulty with exporting the data as a csv. I'm seeking help with programming the form name and version number into the first row and first two columns of the csv. I've been adding the information manually but it's getting tiresome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mmm7_0-1601493486065.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49976i6D825AF725FCA1A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mmm7_0-1601493486065.png" alt="mmm7_0-1601493486065.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 19:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/687956#M79594</guid>
      <dc:creator>mmm7</dc:creator>
      <dc:date>2020-09-30T19:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to add header text in first two columns of row 1 in a csv proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/687994#M79595</link>
      <description>&lt;P&gt;PROC EXPORT creates a data step and runs it. That data step can be found and copy/pasted from the log.&lt;/P&gt;
&lt;P&gt;In this data step there is a statement run at _N_ = 1 that writes the header. You can add your additional header line there.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 20:02:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/687994#M79595</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-30T20:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to add header text in first two columns of row 1 in a csv proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/688167#M79609</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for the guidance! Below is the proc export code from the log. I tried to manipulate the _n_ = 1 statement to meet my needs to no avail. Would you be willing to walk me through this further? I appreciate your time and help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data _null_;
      %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
      %let _EFIREC_ = 0;     /* clear export record count macro variable */
      file 'S:\TEXT.csv' delimiter=',' DSD DROPOVER lrecl=32767;
      if _n_ = 1 then        /* write column names or labels */
       do;
         put
            "VAR1"
         ','
            "VAR2"
         ','
            "VAR3"
         ','
            "VAR4"
         ;
       end;
     set  IMPORT   end=EFIEOD;
         format VAR1 best12. ;
         format VAR2 $1. ;
         format VAR3 best12. ;
         format VAR4 $2. ;
       do;
         EFIOUT + 1;
         put VAR1 @;
         put VAR2 $ @;
         put VAR3 @;
         put VAR4 $ ;
        ;
       end;
      if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
      if EFIEOD then call symputx('_EFIREC_',EFIOUT);
run;&lt;/PRE&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 12:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/688167#M79609</guid>
      <dc:creator>mmm7</dc:creator>
      <dc:date>2020-10-01T12:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to add header text in first two columns of row 1 in a csv proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/688168#M79610</link>
      <description>&lt;P&gt;Add a PUT statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
      %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
      %let _EFIREC_ = 0;     /* clear export record count macro variable */
      file 'S:\TEXT.csv' delimiter=',' DSD DROPOVER lrecl=32767;
      if _n_ = 1 then        /* write column names or labels */
       do;
         put "Form: xxx,Version: yyy";
         put
            "VAR1"
         ','
            "VAR2"
         ','
            "VAR3"
         ','
            "VAR4"
         ;
       end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Oct 2020 12:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/688168#M79610</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-01T12:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to add header text in first two columns of row 1 in a csv proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/688176#M79612</link>
      <description>&lt;P&gt;There is no need to use PROC EXPORT to write a CSV file. A data step will do the same easily.&lt;/P&gt;
&lt;P&gt;Let's assume you have two datasets one named FORM with variables NAME and VERSION and one named HAVE with the data.&amp;nbsp;Let's assume you have a fileref CSV that points to the file you want to create.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First get a list of the names of the variables in the HAVE dataset (so you can write the header row).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have(obs=0) out=names;
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now write the two header rows and the data to the same file.&amp;nbsp; The MOD option on the last two FILE statements means the new lines are appended to the end of the existing file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file csv dsd ;
  set form;
  put name version;
run;
data _null_;
  file csv dsd mod;
  set names;
  put _name_ @@;
run;
data _null_;
  file csv dsd mod;
  set have;
  put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Oct 2020 12:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/688176#M79612</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-01T12:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to add header text in first two columns of row 1 in a csv proc export</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/689948#M79654</link>
      <description>&lt;P&gt;Thanks for your example! It worked perfectly!&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 12:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-add-header-text-in-first-two-columns-of-row-1-in-a-csv/m-p/689948#M79654</guid>
      <dc:creator>mmm7</dc:creator>
      <dc:date>2020-10-08T12:24:58Z</dc:date>
    </item>
  </channel>
</rss>

