<?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: CSV Input when a Variable Contains a Delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414734#M101633</link>
    <description>&lt;P&gt;Read the whole line as one variable and use scan function to put values into first 4 variables,&lt;/P&gt;
&lt;P&gt;then use index function to point at the $ signe, substring the rest of line and input value to salary&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using best informat or comma informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try make your code and come back in case of any issue.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Nov 2017 02:08:11 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2017-11-20T02:08:11Z</dc:date>
    <item>
      <title>CSV Input when a Variable Contains a Delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414717#M101627</link>
      <description>&lt;P&gt;Good Afternoon,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been working my way thru Cody's Learning SAS by Example.&amp;nbsp; Problem 15 in Chapter 3 is giving me some trouble.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The input file contains:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;123,"Harold Wilson", Acct,01/15/1989,$78,123.&lt;BR /&gt;128,"Julia Child",Food, 08/29/1988,$89,123&lt;BR /&gt;007,"James Bond",Security,02/01/2000,$82,100&lt;BR /&gt;828,"Roger Doger",Acct,08/15/1999,$39,100&lt;BR /&gt;900,"Earl Davenport",Food,09/09/1989,$45,399&lt;BR /&gt;906,"James Swindler",Acct,12/21/1978,$78,200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The input is comma delimited, but the last field, SALARY, contains a comma.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the following script, SALARY is truncated to the portion before its embedded comma.&amp;nbsp; Section 3.14 in the book discusses using the ampersand "&amp;amp;" modifier, but that involves altering the input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could read SALARY in pieces (i.e., before and after the comma), do some arithmetic, and re-assemble.&amp;nbsp; I could alter the input so that SALARY is enclosed in quotes.&amp;nbsp; Seems like there should be a more straight forward solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&amp;nbsp; Thanks in advance&amp;nbsp; &lt;SPAN&gt;&lt;STRONG&gt;SAS release: 9.04.01M4P11092016&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data EMPLOY ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;infile '/home/mytest/sasuser.v94/cody/Employee1.csv'&amp;nbsp; dsd missover;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;informat EmpID&amp;nbsp; $3.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;EmpName $20.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Dept&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$8.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;DateHire&amp;nbsp; mmddyy10.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Salary&amp;nbsp;&amp;nbsp;&amp;nbsp; dollar8.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input EmpID &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;EmpName&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Dept&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;DateHire &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Salary&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2017 22:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414717#M101627</guid>
      <dc:creator>danrohde</dc:creator>
      <dc:date>2017-11-19T22:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Input when a Variable Contains a Delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414734#M101633</link>
      <description>&lt;P&gt;Read the whole line as one variable and use scan function to put values into first 4 variables,&lt;/P&gt;
&lt;P&gt;then use index function to point at the $ signe, substring the rest of line and input value to salary&amp;nbsp;&lt;/P&gt;
&lt;P&gt;using best informat or comma informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try make your code and come back in case of any issue.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 02:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414734#M101633</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-11-20T02:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: CSV Input when a Variable Contains a Delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414761#M101649</link>
      <description>&lt;P&gt;Your CSV file is malformed. If the value has a delimiter (or a quote) in it then it should be quoted. If this is a real data file and they are sending you more of them tell them to fix their process so that it generates a validly formatted file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fortunately the problem is in the last field in the line, so you can work around the error.&amp;nbsp; &amp;nbsp;Since it is the last field you can use list mode input to read the beginning columns and then use formatted mode for the last column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: This is an example where using the obsolete MISSOVER option on the INFILE statement instead of the newer (it is probably only 30 years old) TRUNCOVER option could cause a real problem.&amp;nbsp; If you tell SAS to read 8 characters for SALARY and the line only has 7 characters left then with MISSOVER you will get a missing value, but with TRUNCOVER SAS will just use the number of characters that are available.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data EMPLOY ;
  infile '/home/mytest/sasuser.v94/cody/Employee1.csv' dsd truncover;
  length 
    EmpID $3
    EmpName $20
    Dept $8
    DateHire 8
    Salary 8
  ;
  input empid empname dept datehire salary comma32. ;
  informat datehire mmddyy. ;
  format datehire yymmdd10. salary dollar12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also don't define your variables by relying on the side effect of using an INFORMAT statement as the first place you reference the variable. Go ahead and explicitly define them using a LENGTH or ATTRIB statement. Save the INFORMAT statement for when you actually need to attach an INFORMAT to a variable. Note that SAS does not need informats (or formats) for most variable, especially character variables.&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="image.png" style="width: 396px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/16734i60413777C5225E32/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Nov 2017 07:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CSV-Input-when-a-Variable-Contains-a-Delimiter/m-p/414761#M101649</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-20T07:17:15Z</dc:date>
    </item>
  </channel>
</rss>

