<?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: Catching wrong type of data while reading .csv file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241418#M44738</link>
    <description>Thank you! I'll give this a try and "accept as solution" if/when it works. Bruce</description>
    <pubDate>Thu, 31 Dec 2015 18:58:09 GMT</pubDate>
    <dc:creator>brucehughw</dc:creator>
    <dc:date>2015-12-31T18:58:09Z</dc:date>
    <item>
      <title>Catching wrong type of data while reading .csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241412#M44733</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;	%let csvName = &amp;amp;path.\&amp;amp;site.&amp;amp;dateStr.appxReviewTimes.csv ;

	data &amp;amp;site&amp;amp;dateStr.AppxReviewTimes;
    	infile "&amp;amp;csvName" obs=max dsd; 
		length 
		DeviceID $8
		dateStr $10
		startTimeStr endTimeStr $8
		NWS_code $3;
    retain site;
    if _n_ = 1 then site = "&amp;amp;site";
	input dateStr $ NWS_code $ startTimestr $ endTimeStr $ DeviceID $;
&lt;/PRE&gt;
&lt;P&gt;works well to read correct lines such as the first two shown below. Unfortunately, I sometimes get lines such as the third one thrown in. I'd like to ignore the third one. Also, regarding the fourth line, when I see the DeviceID = 'PWD53_02', I'd like to ignore that, too. Any suggestions for catching this error? Thanks very much, Bruce&lt;/P&gt;
&lt;PRE&gt;12/01/2015, R-,23:26:20,23:27:51,PWD53_01
12/01/2015,  C,23:28:05,23:59:50,PWD53_01&lt;BR /&gt;WMO FOR IP- AT TIME 2015-12-01 23:25:51 IS 71&lt;BR /&gt;12/01/2015, C,00:00:05,00:17:50,PWD53_02&lt;BR /&gt;
&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Dec 2015 18:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241412#M44733</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2015-12-31T18:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Catching wrong type of data while reading .csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241415#M44735</link>
      <description>&lt;P&gt;If possible I recommend going to the source and seeing if the layout can be corrected. Knowing that isn't possible then you end up with any of a number of approaches.&lt;/P&gt;
&lt;P&gt;One depends on what you want. If you do not want the error lines in the output data set something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if input(datestr,mmddyy10.) = . then delete; would remove the lines where the first variable isn't valid date.&lt;/P&gt;
&lt;P&gt;For any specific values you don't want in your data set then similar:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if device= "PWD53_02" then delete;&lt;/P&gt;
&lt;P&gt;If there are multiple values for a variable you don't want use IN operator to use a list:&lt;/P&gt;
&lt;P&gt;If device in ("PWD53_02" "PWD53_04" "PWD54_02") then delete;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2015 18:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241415#M44735</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-12-31T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Catching wrong type of data while reading .csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241418#M44738</link>
      <description>Thank you! I'll give this a try and "accept as solution" if/when it works. Bruce</description>
      <pubDate>Thu, 31 Dec 2015 18:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241418#M44738</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2015-12-31T18:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Catching wrong type of data while reading .csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241431#M44747</link>
      <description>&lt;P&gt;I would suggest analysing the input line before it is parsed as a CSV string:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;site&amp;amp;dateStr.AppxReviewTimes;
infile "&amp;amp;csvName" dsd; 
length 
	DeviceID $8
	dateStr $10
	startTimeStr endTimeStr $8
	NWS_code $3;
retain site;
if _n_ = 1 then site = "&amp;amp;site";
input @;
if notdigit(substr(_infile_, 1, 2)) ne 0 then delete;
input dateStr NWS_code startTimestr endTimeStr DeviceID;
if deviceID="PWD53_02" then delete;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Dec 2015 20:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241431#M44747</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-12-31T20:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Catching wrong type of data while reading .csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241637#M44799</link>
      <description>&lt;P&gt;Thanks, PG. I will try this. Could you please help me out with a couple questions? In&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;input @;
if notdigit(substr(_infile_, 1, 2)) ne 0 then delete;
input dateStr NWS_code startTimestr endTimeStr DeviceID;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN style="line-height: 20px;"&gt;does the first statement read the entire line of the .csv file (I assume it does)&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN style="line-height: 20px;"&gt;_infile_ must be what was just read by the previous statement, correct? Where is this documented? I have not seen this before.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;thanks very much, Bruce&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2016 13:28:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241637#M44799</guid>
      <dc:creator>brucehughw</dc:creator>
      <dc:date>2016-01-04T13:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: Catching wrong type of data while reading .csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241670#M44808</link>
      <description>&lt;P&gt;1) yes.&lt;/P&gt;
&lt;P&gt;2) Google&amp;nbsp;site:support.sas.com "_INFILE_"&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jan 2016 15:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Catching-wrong-type-of-data-while-reading-csv-file/m-p/241670#M44808</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-01-04T15:57:48Z</dc:date>
    </item>
  </channel>
</rss>

