<?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 Selectively Quote variables when output them to csv. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822332#M324721</link>
    <description>&lt;P&gt;So I do the below, and it quotes some variables when they have a comma in them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want put quotes on selective column like &lt;STRONG&gt;Horsepower ONLY.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please adivse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data _null_;
    file "/path/output/unix/cars.csv"
    dsd dlm = ',';
    set sashelp.cars;
    if _n_ = 1 then put @1 
    "Make,Model,Type,Origin,DriveTrain,MSRP,Invoice,EngineSize,Cylinders,Horsepower,MPG_City,MPG_Highway,Weight,Wheelbase,Length"; 
    put Make
		Model
		Type
		Origin
		DriveTrain
		MSRP
		Invoice
		EngineSize
		Cylinders
		Horsepower
		MPG_City
		MPG_Highway
		Weight
		Wheelbase
		Length;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Jul 2022 18:27:34 GMT</pubDate>
    <dc:creator>david27</dc:creator>
    <dc:date>2022-07-08T18:27:34Z</dc:date>
    <item>
      <title>Selectively Quote variables when output them to csv.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822332#M324721</link>
      <description>&lt;P&gt;So I do the below, and it quotes some variables when they have a comma in them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want put quotes on selective column like &lt;STRONG&gt;Horsepower ONLY.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please adivse.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data _null_;
    file "/path/output/unix/cars.csv"
    dsd dlm = ',';
    set sashelp.cars;
    if _n_ = 1 then put @1 
    "Make,Model,Type,Origin,DriveTrain,MSRP,Invoice,EngineSize,Cylinders,Horsepower,MPG_City,MPG_Highway,Weight,Wheelbase,Length"; 
    put Make
		Model
		Type
		Origin
		DriveTrain
		MSRP
		Invoice
		EngineSize
		Cylinders
		Horsepower
		MPG_City
		MPG_Highway
		Weight
		Wheelbase
		Length;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822332#M324721</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2022-07-08T18:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Selectively Quote variables when output them to csv.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822335#M324722</link>
      <description>&lt;P&gt;You can force PUT to add quotes even when the value being written does not need them by using the ~ modifier.&lt;/P&gt;
&lt;P&gt;Example:&amp;nbsp; You see that the values of MSRP require quotes because they contain the delimiter, but values for ENGINESIZE and MODEL do not.&lt;/P&gt;
&lt;PRE&gt;428  data _null_;
429    set sashelp.cars(obs=5);
430    file log dsd ;
431  put
432    Make
433    Model
434    MSRP
435    EngineSize
436    Cylinders
437    Horsepower ~
438    MPG_City
439  ;
440  run;

Acura,MDX,"$36,945",3.5,6,"265",17
Acura,RSX Type S 2dr,"$23,820",2,4,"200",24
Acura,TSX 4dr,"$26,990",2.4,4,"200",22
Acura,TL 4dr,"$33,195",3.2,6,"270",20
Acura,3.5 RL 4dr,"$43,755",3.5,6,"225",18
NOTE: There were 5 observations read from the data set SASHELP.CARS.
&lt;/PRE&gt;
&lt;P&gt;But why would you want to make your output file larger than it needs to be?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822335#M324722</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-08T18:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Selectively Quote variables when output them to csv.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822336#M324723</link>
      <description>&lt;P&gt;To match someone else's output for validation purposes.&lt;/P&gt;&lt;P&gt;Why this other person adds quotes around variables that don't need it-- I have no idea.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822336#M324723</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2022-07-08T18:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Selectively Quote variables when output them to csv.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822337#M324724</link>
      <description>&lt;P&gt;Quick question:&lt;BR /&gt;Is there a way to conditionally quote the values?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;For example-- put quotes only if the horsepower is more than 250?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jul 2022 18:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822337#M324724</guid>
      <dc:creator>david27</dc:creator>
      <dc:date>2022-07-08T18:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Selectively Quote variables when output them to csv.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822339#M324726</link>
      <description>&lt;P&gt;Use IF statement.&lt;/P&gt;
&lt;PRE&gt;458  data _null_;
459    set sashelp.cars(obs=5);
460    file log dsd ;
461  put
462    Make
463    Model
464    MSRP
465    EngineSize
466    Cylinders
467    @
468  ;
469  if horsepower &amp;gt; 250 then put Horsepower ~ @;
470  else put Horsepower @;
471  put
472    MPG_City
473  ;
474  run;

Acura,MDX,"$36,945",3.5,6,"265",17
Acura,RSX Type S 2dr,"$23,820",2,4,200,24
Acura,TSX 4dr,"$26,990",2.4,4,200,22
Acura,TL 4dr,"$33,195",3.2,6,"270",20
Acura,3.5 RL 4dr,"$43,755",3.5,6,225,18
NOTE: There were 5 observations read from the data set SASHELP.CARS.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jul 2022 19:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selectively-Quote-variables-when-output-them-to-csv/m-p/822339#M324726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-08T19:03:06Z</dc:date>
    </item>
  </channel>
</rss>

