<?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 a header text in the first row and column cell in SAS csv output? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920827#M41275</link>
    <description>&lt;P&gt;My report has a requirement to have specific report header it the first row (Cell1) and then save th eoutput as csv shoing column labels since column names don't match the required naming convention. I am using SAS Enterprise Guide 8.3 and managed to export the variable lables rahter than names. However, I still can't get to include the header in the first cell. Here are suggested codes:&lt;/P&gt;&lt;DIV&gt;DATA _null_;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FILE "C:\output.csv" DLM="," ;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; PUT "Consent";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; PUT;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC EXPORT DATA=FINAL&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; OUTFILE="C:\output.csv"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DBMS=CSV&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; REPLACE&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LABEL;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PUTNAMES=Yes;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;P&gt;---------------------------------------------------------&lt;/P&gt;&lt;P&gt;The codes didn't generate any eorros but didn't add the text in the first row either. I appreciate any suggestions?&lt;/P&gt;&lt;P&gt;desired csv output:&lt;/P&gt;&lt;P&gt;First Row: Consent&lt;/P&gt;&lt;P&gt;Second Row: Data Column Labels (rahter names)&lt;/P&gt;&lt;P&gt;Third row on: Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Mar 2024 19:44:58 GMT</pubDate>
    <dc:creator>Helal</dc:creator>
    <dc:date>2024-03-18T19:44:58Z</dc:date>
    <item>
      <title>how to add a header text in the first row and column cell in SAS csv output?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920827#M41275</link>
      <description>&lt;P&gt;My report has a requirement to have specific report header it the first row (Cell1) and then save th eoutput as csv shoing column labels since column names don't match the required naming convention. I am using SAS Enterprise Guide 8.3 and managed to export the variable lables rahter than names. However, I still can't get to include the header in the first cell. Here are suggested codes:&lt;/P&gt;&lt;DIV&gt;DATA _null_;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; FILE "C:\output.csv" DLM="," ;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; PUT "Consent";&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; PUT;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;PROC EXPORT DATA=FINAL&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; OUTFILE="C:\output.csv"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DBMS=CSV&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; REPLACE&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LABEL;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PUTNAMES=Yes;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;RUN;&lt;/DIV&gt;&lt;P&gt;---------------------------------------------------------&lt;/P&gt;&lt;P&gt;The codes didn't generate any eorros but didn't add the text in the first row either. I appreciate any suggestions?&lt;/P&gt;&lt;P&gt;desired csv output:&lt;/P&gt;&lt;P&gt;First Row: Consent&lt;/P&gt;&lt;P&gt;Second Row: Data Column Labels (rahter names)&lt;/P&gt;&lt;P&gt;Third row on: Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 19:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920827#M41275</guid>
      <dc:creator>Helal</dc:creator>
      <dc:date>2024-03-18T19:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a header text in the first row and column cell in SAS csv output?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920856#M41276</link>
      <description>&lt;P&gt;Delimited files with no headers are TRIVIAL to create with SAS data step (see the last step below).&amp;nbsp;&amp;nbsp;And it takes only a little extra effort to generate a header row first.&amp;nbsp; You could add your extra headers line at that point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First get the names and labels (if any) of the variables into a dataset.&amp;nbsp; PROC TRANSPOSE with zero input observations is a simple way to do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=FINAL(obs=0) out=names;
  var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now use that dataset of names to write your first two lines. You can use COALESCEC() to have it use the NAME when the variable does not have a LABEL attached.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file  "C:\output.csv" dsd;
  length _name_ $32 _label_ $256 ;
  set names;
  if _n_=1 then put 'Consent';
  _label_=coalescec(_label_,_name_);
  put _label_ @ ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then just run a second data step to append the actual data lines by adding the MOD option to the FILE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file  "C:\output.csv" dsd mod;
  set FINAL;
  put (_all_) (+0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 00:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920856#M41276</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-19T00:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a header text in the first row and column cell in SAS csv output?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920865#M41277</link>
      <description>&lt;P&gt;Thank you Tom. It worked like a charm.&lt;/P&gt;&lt;P&gt;Helal&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 02:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920865#M41277</guid>
      <dc:creator>Helal</dc:creator>
      <dc:date>2024-03-19T02:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to add a header text in the first row and column cell in SAS csv output?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920867#M41278</link>
      <description>&lt;P&gt;You gotta need CSVALL destination,&lt;/P&gt;
&lt;P&gt;but if you have a big table, this way would be very slowly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data FINAL;
 set sashelp.class;
 label sex='sex  sfder';
run;

ods _all_ close;
ods csvall file='c:\temp\a\output.csv';
title;
ods text='Consent';
proc report data=final nowd ;
define _all_/display;
run;
ods csvall close;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1710815951563.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/94746iB666B112EBA2338E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1710815951563.png" alt="Ksharp_0-1710815951563.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2024 02:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-add-a-header-text-in-the-first-row-and-column-cell-in-SAS/m-p/920867#M41278</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-03-19T02:39:17Z</dc:date>
    </item>
  </channel>
</rss>

