<?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: Adding Column Names Using PUT Statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161252#M263365</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Works perfectly!&amp;nbsp; Thanks for all the quick responses.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Jun 2014 14:34:36 GMT</pubDate>
    <dc:creator>pjm294</dc:creator>
    <dc:date>2014-06-30T14:34:36Z</dc:date>
    <item>
      <title>Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161247#M263360</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using the following code to produce a text file:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename outfile 'C:\Users\pjm294\Desktop\somefile.txt';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file outfile dsd dlm=',';&lt;/P&gt;&lt;P&gt;&amp;nbsp; set work.somedata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; put&amp;nbsp; (_all_) (~);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output I desire is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Code","Name","State"&lt;/P&gt;&lt;P&gt;"1","John","Pennsylvania"&lt;/P&gt;&lt;P&gt;"2","Jeff","Maryland"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However the above code lacks the column names I need.&amp;nbsp; The code produces the following output:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;"1","John","Pennsylvania"&lt;/P&gt;&lt;P&gt;"2","Jeff","Maryland"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Is there a way to add the column names using the PUT statement?&amp;nbsp; The file I am creating it part of a process, which this file goes to a vendor for further processing. Their programming requires the file to have column names and all data elements in double quotes with each field separated by commas.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 13:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161247#M263360</guid>
      <dc:creator>pjm294</dc:creator>
      <dc:date>2014-06-30T13:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161248#M263361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just add:&lt;/P&gt;&lt;P&gt; if _n_=1 then put "Code","Name","State";&lt;/P&gt;&lt;P&gt;before the put (_all_) (~);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 14:01:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161248#M263361</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-30T14:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161249#M263362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That answer works, however I should have specified in the original post that this was just an example.&amp;nbsp; The actual process has hundreds of field names that change from file to file depending on the data.&amp;nbsp; I want to automate the entire process and if I have to add the individual column names as suggested by your answer I am no further ahead.&amp;nbsp; Apologies for not clarifying in the original question. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 14:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161249#M263362</guid>
      <dc:creator>pjm294</dc:creator>
      <dc:date>2014-06-30T14:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161250#M263363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No probs. &lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :VARL_LIST separated be '","'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SASHELP.VCOLUMN&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LIBNAME="xxxx" and MEMNAME="xxxx";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if _n_=1 then put "&amp;amp;VAR_LIST.";&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 14:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161250#M263363</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-06-30T14:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161251#M263364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="814511" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt;'s suggestion is on the right direction, except some details need to be tweaked. Since you used DSD, meaning you want your output data to be comma delimited and quoted, you would need more work to polish the macro variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;filename outfile 'C:\Users\pjm294\Desktop\somefile.txt';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select quote(CATS(name)) into :name SEPARATED BY ',' from dictionary.columns where LIBNAME='WORK' AND MEMNAME='SOMEDATA';QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file outfile dsd dlm=',';&lt;/P&gt;&lt;P&gt;&amp;nbsp; set SOMEDATA;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF _N_=1 THEN PUT "%BQUOTE(&amp;amp;NAME)";&lt;/P&gt;&lt;P&gt;&amp;nbsp; put (_all_) (~);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 14:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161251#M263364</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2014-06-30T14:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161252#M263365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Works perfectly!&amp;nbsp; Thanks for all the quick responses.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 14:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161252#M263365</guid>
      <dc:creator>pjm294</dc:creator>
      <dc:date>2014-06-30T14:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161253#M263366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Why do you want quotes around EVERY value?&amp;nbsp; SAS will put in the quotes where they are needed. They take up a lot of extra space in the file and unless you are forced to send this data to some brain dead system they should not be needed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;You can also write the names in a separate step before the data. For example here is method using PROC TRANSPOSE to generate the variable names into a dataset for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=work.somedata&lt;STRONG&gt;(obs=0)&lt;/STRONG&gt; out=names ;&lt;/P&gt;&lt;P&gt;var _all_;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set names end=eof ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file outfile dsd lrecl=30000 ;&lt;/P&gt;&lt;P&gt;put _name_ @ ;&lt;/P&gt;&lt;P&gt;if eof then put ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then in your data step that writes the data add the MOD option to the FILE statement to append that data to the file with the header line.&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set work.somedata ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; file outfile dsd&lt;STRONG&gt; MOD&lt;/STRONG&gt; lrecl=30000 ;&lt;/P&gt;&lt;P&gt;put (_all_) (:) ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Code,Name,State&lt;/P&gt;&lt;P&gt;1,John,Pennsylvania&lt;/P&gt;&lt;P&gt;2,Jeff,Maryland&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 00:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161253#M263366</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-07-01T00:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Column Names Using PUT Statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161254#M263367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the response Tom, but a solution was already provided by &lt;A _jive_internal="true" data-avatarid="1025" data-externalid="" data-online="false" data-presence="null" data-userid="5068" data-username="Hai.kuo" href="https://communities.sas.com/people/Hai.kuo" style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #8ca9cd; background-color: #ffffff;"&gt;Hai.kuo.&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Jul 2014 12:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-Column-Names-Using-PUT-Statement/m-p/161254#M263367</guid>
      <dc:creator>pjm294</dc:creator>
      <dc:date>2014-07-01T12:21:43Z</dc:date>
    </item>
  </channel>
</rss>

