<?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: Import from open data source in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627132#M185047</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114180"&gt;@coladuck&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here some code which removes the LF in the data before using Proc Import.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename incsv url "https://data.medicare.gov/resource/4pq5-n9py.csv" recfm=n lrecl=1;
filename tmpcsv temp recfm=n;

data _null_;
  length _isString 3;
  retain _isString 0;
  file tmpcsv;
  infile incsv;
  input ;
  if _infile_='"' then _isString= (_isString=0);
  if _isString=1 and _infile_='0A'x then _infile_=' ';
  put _infile_ @@;
run;

filename outcsv "%sysfunc(pathname(tmpcsv))" lrecl=1000;
proc import datafile=outcsv out=test2 replace dbms=csv; 
run;

filename tmpcsv clear;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Feb 2020 09:26:41 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-02-25T09:26:41Z</dc:date>
    <item>
      <title>Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627069#M185018</link>
      <description>&lt;P&gt;Hi, I try to import data from open data source using the following code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;filename csvFile url "https://data.medicare.gov/resource/4pq5-n9py.csv";

proc import datafile=csvFile out=test2 replace dbms=csv; run;&lt;/PRE&gt;&lt;P&gt;The program runs but data are not imported correctly. Strange rows are showing up, messing up everything.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36377i30B511B54F338A97/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Anything I missed? Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 01:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627069#M185018</guid>
      <dc:creator>coladuck</dc:creator>
      <dc:date>2020-02-25T01:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627075#M185020</link>
      <description>&lt;P&gt;This is probably an excel export. The lines include an LF character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can add the &lt;SPAN&gt;IGNOREDOSEOF&amp;nbsp;&lt;/SPAN&gt;option to the INFILE statement.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 02:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627075#M185020</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-25T02:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627076#M185021</link>
      <description>&lt;P&gt;Sadly SAS &lt;A href="https://communities.sas.com/t5/SASware-Ballot-Ideas/Enhancements-to-INFILE-FILE-to-handle-delimited-file-variations/idi-p/435977" target="_self"&gt;will not&lt;/A&gt; get smarter about quoted LF characters in CSV files.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 02:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627076#M185021</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-02-25T02:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627084#M185024</link>
      <description>&lt;P&gt;The challenge is that LF is both the end-of-line indicator and part of data. The only thing which keeps things apart is that the LF characters which are part of data are within double quotes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SAS Import Procedure (and data step) are both not great at dealing with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is a one-off task then first download the file vie browser to your local machine and then use the EG Import Wizard.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's a repeated task then you need to pre-process the file and remove the LF within quotes. If you search a bit the forum here then you'll find several existing discussions/solutions for this.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 03:09:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627084#M185024</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-25T03:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627085#M185025</link>
      <description>Agreed that this sucks! This seems consistent with how scripting languages still work, but R/Python both have this figured out. I spent way too much time recently debugging this issue because the command line count didn't match the imported count - because there was an extra LF in some columns. Ironically, it didn't matter because R had read it correctly so it wasn't the source of the issue but it still was a pain in the a**.</description>
      <pubDate>Tue, 25 Feb 2020 03:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627085#M185025</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-25T03:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627132#M185047</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114180"&gt;@coladuck&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here some code which removes the LF in the data before using Proc Import.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename incsv url "https://data.medicare.gov/resource/4pq5-n9py.csv" recfm=n lrecl=1;
filename tmpcsv temp recfm=n;

data _null_;
  length _isString 3;
  retain _isString 0;
  file tmpcsv;
  infile incsv;
  input ;
  if _infile_='"' then _isString= (_isString=0);
  if _isString=1 and _infile_='0A'x then _infile_=' ';
  put _infile_ @@;
run;

filename outcsv "%sysfunc(pathname(tmpcsv))" lrecl=1000;
proc import datafile=outcsv out=test2 replace dbms=csv; 
run;

filename tmpcsv clear;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Feb 2020 09:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627132#M185047</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-25T09:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627245#M185102</link>
      <description>&lt;P&gt;Thank you everyone for the great inputs!! Patrick's code works beautifully so I accepted it as the solution. Now need to spend some time understanding the code!&amp;nbsp;&lt;img id="smileylol" class="emoticon emoticon-smileylol" src="https://communities.sas.com/i/smilies/16x16_smiley-lol.png" alt="Smiley LOL" title="Smiley LOL" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 17:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627245#M185102</guid>
      <dc:creator>coladuck</dc:creator>
      <dc:date>2020-02-25T17:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Import from open data source</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627351#M185177</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114180"&gt;@coladuck&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you everyone for the great inputs!! Patrick's code works beautifully so I accepted it as the solution. Now need to spend some time understanding the code!&amp;nbsp;&lt;img id="smileylol" class="emoticon emoticon-smileylol" src="https://communities.sas.com/i/smilies/16x16_smiley-lol.png" alt="Smiley LOL" title="Smiley LOL" /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Even after removing the LF between the quotes it looks to me Proc Import still doesn't read the data as one would wish for. One reason is that all strings are within quotes so Proc Import treats them all as character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're likely better off if you write a SAS data step. Take EG import wizard generated code (or use Proc Import generated code from the SAS log) and then amend the code so you really get what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've attached the source data with the LF removed. This is what you get under fileref&amp;nbsp;&lt;EM&gt;outcsv&lt;/EM&gt; from the code you've marked as solution.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 22:13:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-from-open-data-source/m-p/627351#M185177</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-25T22:13:40Z</dc:date>
    </item>
  </channel>
</rss>

