<?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: ODS CSV output... unable to print a few variable with quotes in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270394#M15890</link>
    <description>&lt;P&gt;You probably can't put functions in a put statement, I didn't test teh code. &amp;nbsp;Try the below. &amp;nbsp;I would still advise you not put variable names with quotes around them, its not CSV and I wouldn't accept that datafile.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  length tmp $2000;
  set your_data;
  file "somewhere\your_file.txt";
  if _n_=1 then put '"Variable_1","Variable_2","Variable_3"';
  tmp=catx(",",quote(variable_1),quote(variable_2),quote(variable_3));
  put tmp;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 13 May 2016 16:05:19 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-05-13T16:05:19Z</dc:date>
    <item>
      <title>ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270335#M15878</link>
      <description>&lt;P&gt;Hi, I want to create a CSV File with the variable names and values in quotes&amp;nbsp;like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"Variable_1","Variable_2","Variable_3"&lt;/P&gt;&lt;P&gt;"Value_11","Value_21","Value_31"&lt;/P&gt;&lt;P&gt;"Value_12","Value_22","Value_32"&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm unable to get the values for three variables in quotes while the rest six&amp;nbsp;are coming in quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can someone suggest what could be the reason for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using SAS 9.3 and the code i'm using is :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ODS CSV File = 'H:\Reports\test.csv' noobs;&lt;/P&gt;&lt;P&gt;proc print data = data3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;ODS CSV CLOSE:&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 13:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270335#M15878</guid>
      <dc:creator>Saurabh_1</dc:creator>
      <dc:date>2016-05-13T13:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270342#M15879</link>
      <description>&lt;P&gt;The reason is that standard CSV file format (&lt;A href="https://en.wikipedia.org/wiki/Comma-separated_values)" target="_blank"&gt;https://en.wikipedia.org/wiki/Comma-separated_values)&lt;/A&gt; is thus:&lt;BR /&gt;Line 1 contains each variable name separate by a column [Note: optional]&lt;/P&gt;
&lt;P&gt;Line &amp;gt; 1 contains each row of data on per line, with data items separated by commas, with the option of quoting data items where its possible special characters may impact the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will note that the first line shows Variable names - these would not be quoted. &amp;nbsp;If you really want this (and why?) then you would need to do it by hand in a datastep output - although be sure to not call the file CSV as it wouldn't be a CSV.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set your_data;
  file "somewhere\your_file.txt";
  if _n_=1 then put '"Variable_1","Variable_2","Variable_3"';
  put catx(",",quote(variable_1),quote(variable_2),quote(variable_3));
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 13:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270342#M15879</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-13T13:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270358#M15881</link>
      <description>&lt;P&gt;Thank you for your reply RW9. Actually, I'm getting the Variable Names in quotes using my earlier code so the issue is only with values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also when i run the code you've provided i'm getting this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;112 data _null_;&lt;/P&gt;&lt;P&gt;113 set RSF_Data3;&lt;/P&gt;&lt;P&gt;114 file 'H:\reports\test2.txt';&lt;/P&gt;&lt;P&gt;115 if _n_ = 1 then put&lt;/P&gt;&lt;P&gt;115! '"Account_number","Name","date_deceased","balance_amt_dod","City","St","Zip"';&lt;/P&gt;&lt;P&gt;116 put catx("," ,&lt;/P&gt;&lt;P&gt;---&lt;/P&gt;&lt;P&gt;22&lt;/P&gt;&lt;P&gt;76&lt;/P&gt;&lt;P&gt;116! quote(Account_number),quote(Name),quote(date_deceased),quote(balance_amt_dod),quote(City),&lt;/P&gt;&lt;P&gt;116! quote(ST),quote(Zip));&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, arrayname, _ALL_,&lt;/P&gt;&lt;P&gt;_CHARACTER_, _CHAR_, _NUMERIC_.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;117 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;/P&gt;&lt;P&gt;real time 0.01 seconds&lt;/P&gt;&lt;P&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing is that my data has missing values, so i'm not sure if catx would be the right function&amp;nbsp;in this case.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 14:45:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270358#M15881</guid>
      <dc:creator>Saurabh_1</dc:creator>
      <dc:date>2016-05-13T14:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270394#M15890</link>
      <description>&lt;P&gt;You probably can't put functions in a put statement, I didn't test teh code. &amp;nbsp;Try the below. &amp;nbsp;I would still advise you not put variable names with quotes around them, its not CSV and I wouldn't accept that datafile.&lt;/P&gt;
&lt;PRE&gt;data _null_;
  length tmp $2000;
  set your_data;
  file "somewhere\your_file.txt";
  if _n_=1 then put '"Variable_1","Variable_2","Variable_3"';
  tmp=catx(",",quote(variable_1),quote(variable_2),quote(variable_3));
  put tmp;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 16:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270394#M15890</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-13T16:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270398#M15891</link>
      <description>&lt;P&gt;Or use the tilde modifier to simplify the PUT statement for the variable values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set RSF_Data3;
file 'H:\reports\test2.txt' dsd;
if _n_ = 1 then put '"Account_number","Name","date_deceased","balance_amt_dod","City","St","Zip"';
put (_all_)(~);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that the variable names in the first PUT statement are listed in the same order as they are stored in the dataset. The DSD option of the FILE statement implies specifying comma as the delimiter. With a bit more effort you can even create the list of variable names automatically: see &lt;A href="https://communities.sas.com/t5/SAS-Procedures/Reading-from-sashelp-vcolumn-is-taking-too-long/m-p/189970#M47958" target="_blank"&gt;this older post&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 16:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270398#M15891</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-13T16:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270491#M15908</link>
      <description>&lt;PRE&gt;
use options(doc='help') to get the what kind of option you can used in ODS CSV:

ODS CSV File = 'c:\temp\test.csv' options(doc='help');
proc print data = sashelp.class noobs;
run;
ODS CSV CLOSE;





especially these option:
quote_by_type='yes'
quoted_columns='1234'



ODS CSV File = 'c:\temp\test.csv' options( quoted_columns='1234');
proc print data = sashelp.class noobs;
run;
ODS CSV CLOSE;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 14 May 2016 06:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270491#M15908</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-14T06:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: ODS CSV output... unable to print a few variable with quotes</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270510#M15909</link>
      <description>&lt;P&gt;What ODS CSV produces is not a real CSV file. It adds too many quotes and it also adds an extra line at the end. &amp;nbsp;But it sounds like what you want is not a real CSV file either. &amp;nbsp;Fortunately it is easy with SAS to produce both a real CSV file and what you want with just a couple of simple steps.&lt;/P&gt;
&lt;P&gt;First let's get some test data to use. &amp;nbsp;For example the first three records in SASHELP.CLASS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test; set sashelp.class(obs=3); run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's set the output location. &amp;nbsp;I will use a temp file for this demonstration.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first line of the CSV file is usually the variable names (column headers). &amp;nbsp;You can generate that easily using a couple of steps.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=test(obs=0) ;
  var _all_;
run;
data _null_;
  file csv dsd ;
  set &amp;amp;syslast end=eof;
  put _name_ @;
  if eof then put ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now&amp;nbsp;to write the data lines we just add one more data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  file csv dsd mod;
  set test ;
  put (_all_) (+0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To check if the result is in the proper format let's run a simple data step to show the lines from the output file back into the SAS log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile csv;
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So for our little three observation test case the result is the well formed CSV file below. &amp;nbsp;Note that there are no unneeded quote characters or extra blank lines.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Name,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To add all of those extra quote characters that you requested you just need to add the ~ modifier to the put statements. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in the step that writes the variable names you would use this PUT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  put _name_ ~ @;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And in the step that writes the variable values you would use this PUT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  put (_all_) (~) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With those changes the resulting file will look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"Name","Sex","Age","Height","Weight"
"Alfred","M","14","69","112.5"
"Alice","F","13","56.5","84"
"Barbara","F","13","65.3","98"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2016 12:57:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/ODS-CSV-output-unable-to-print-a-few-variable-with-quotes/m-p/270510#M15909</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-05-14T12:57:59Z</dc:date>
    </item>
  </channel>
</rss>

