<?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 a crazy csv file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946197#M370577</link>
    <description>&lt;P&gt;The best way to read this file into SAS is to use the Data Step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data test;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; infile "c:\temp\test_Eems.csv" dlm=';' dsd missover firstobs=2;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; input Datnum : $15.&amp;nbsp; Url : $100. Sentiment : $10. Type : $10.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Discussie_Lengte : 8. Views : 8.&amp;nbsp; Auteur : $25.&amp;nbsp; Volgers : 8.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Bron : $15. Title : $200. Bericht : $300.&amp;nbsp; Labels : $10.;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc print data=test;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;The above method uses the Modified List Input method&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0lrz3gb7m9e4rn137op544ddg0v.htm#p1wk2kecsf6iz8n1ufug4i5pg6id" target="_blank"&gt;SAS Help Center: INPUT Statement: List&lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2024 20:51:53 GMT</pubDate>
    <dc:creator>JOL</dc:creator>
    <dc:date>2024-10-03T20:51:53Z</dc:date>
    <item>
      <title>import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946154#M370563</link>
      <description>&lt;P&gt;I tried to import a file in csv format in sas but not without problem.&lt;BR /&gt;First I did it normally like:&lt;BR /&gt;proc import datafile=reffile&lt;BR /&gt;out=test_Eems&lt;BR /&gt;dbms=csv&lt;BR /&gt;replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;BR /&gt;without success and I saw in the log that there could be talk of delimiter ';'.&lt;BR /&gt;So I added delimiter ';'.&lt;/P&gt;&lt;P&gt;proc import datafile=reffile&lt;BR /&gt;out=test_Eems&lt;BR /&gt;dbms=csv&lt;BR /&gt;replace;&lt;BR /&gt;delimiter=";" ;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;I get a better result but not always correct because a column (called Bericht) contains all kinds of characters also the semicolon.&lt;BR /&gt;Of course I get an error in the log.&lt;BR /&gt;What surprises me is that I could open the same file without problem in Excel or a google sheet but not in Sas.&lt;BR /&gt;I have converted the same file to an excel file using excel and I could easily read and open it in sas.&lt;/P&gt;&lt;P&gt;My question to you is if I could open the file in Excel and google sheet then it should also work in Sas.&lt;BR /&gt;I would like your help with that.&lt;BR /&gt;Below are the file that I could not import in csv format but in excel and the log that I got when I tried with csv format&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 15:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946154#M370563</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-10-03T15:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946168#M370564</link>
      <description>&lt;P&gt;I suspect your file as embedded LF characters?&lt;/P&gt;
&lt;P&gt;Try telling SAS to use TERMSTR=CRLF when reading the file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile reffile dsd dlm=';' firstobs=2 termstr=crlf truncover;
  input (var1-var12) (:$200.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to continue to use PROC IMPORT to make GUESSES about what the variables are and what types of data the variables have then you can add the TERMSTR= option to the FILENAME statement that defined the fileref REFFILE you used in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename reffile 'physical filename' termstr=crlf ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I use CSV2DS macro to guess how to read the file it defines the variables this way:&lt;/P&gt;
&lt;PRE&gt;1089 +data test2;
1090 +  infile CSV termstr=crlf dlm=';' dsd truncover firstobs=2 ;
1091 +  length Datum 8 Url $341 Sentiment $8 Type $7 Discussie_lengte 8 Views 8
1092 +    Auteur $81 Volgers 8 Bron $9 Titel $172 Bericht $9010 Labels $1
1093 +  ;
1094 +  informat Datum anydtdtm. ;
1095 +  format Datum datetime19. ;
1096 +  label Discussie_lengte='Discussie lengte' ;
1097 +  input Datum -- Labels ;
1098 +run;

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 16:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946168#M370564</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-03T16:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946197#M370577</link>
      <description>&lt;P&gt;The best way to read this file into SAS is to use the Data Step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data test;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; infile "c:\temp\test_Eems.csv" dlm=';' dsd missover firstobs=2;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; input Datnum : $15.&amp;nbsp; Url : $100. Sentiment : $10. Type : $10.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Discussie_Lengte : 8. Views : 8.&amp;nbsp; Auteur : $25.&amp;nbsp; Volgers : 8.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; Bron : $15. Title : $200. Bericht : $300.&amp;nbsp; Labels : $10.;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc print data=test;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;The above method uses the Modified List Input method&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0lrz3gb7m9e4rn137op544ddg0v.htm#p1wk2kecsf6iz8n1ufug4i5pg6id" target="_blank"&gt;SAS Help Center: INPUT Statement: List&lt;/A&gt;&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 20:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946197#M370577</guid>
      <dc:creator>JOL</dc:creator>
      <dc:date>2024-10-03T20:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946213#M370582</link>
      <description>&lt;P&gt;Using the SAS EG import wizard to generate data step code appears to work.&lt;/P&gt;
&lt;P&gt;Below the generated code with some manual changes applied (like longer character variables so they hopefully are also sufficiently long for all your data and not only the sample).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.test_Eems;
    LENGTH
        Datum              8
        Url              $ 500
        Sentiment        $ 8
        Type             $ 7
        Discussie_lengte   8
        Views              8
        Auteur           $ 250
        Volgers            8
        Bron             $ 9
        Titel            $ 250
        Bericht          $ 1500
        Labels           $ 10 ;
    LABEL
        Discussie_lengte = "Discussie lengte" ;
    FORMAT
        Datum            date9.
        Url              $500.
        Sentiment        $8.
        Type             $7.
        Discussie_lengte best32.
        Views            best32.
        Auteur           $250.
        Volgers          best32.
        Bron             $9.
        Titel            $250.
        Bericht          $1500.
        Labels           $10. ;
    INFORMAT
        Datum            ddmmyy20.
        Url              $500.
        Sentiment        $8.
        Type             $7.
        Discussie_lengte best32.
        Views            best32.
        Auteur           $250.
        Volgers          best32.
        Bron             $9.
        Titel            $250.
        Bericht          $1500.
        Labels           $10. ;
    INFILE 'C:\temp\test_Eems.csv'
        LRECL=30000
        ENCODING="UTF-8"
        TERMSTR=CRLF
        DLM=';'
        truncover
        DSD ;
    INPUT
        Datum            
        Url              
        Sentiment        
        Type             
        Discussie_lengte 
        Views            
        Auteur           
        Volgers          
        Bron             
        Titel            
        Bericht          
        Labels   
        ; 
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Oct 2024 03:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946213#M370582</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-04T03:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946498#M370658</link>
      <description>&lt;P&gt;Thank you for your answer.&lt;BR /&gt;I like it and it all works.&lt;BR /&gt;But I am still a beginner and the original file(Eems_Dollard.csv) had a starting column called "Zoekopdracht".&lt;BR /&gt;When i apply your answer to the original file it does not work and I do not know why.&lt;BR /&gt;If you succeed I would like to hear from you.&lt;BR /&gt;Thanks again for the effort.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 10:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946498#M370658</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-10-07T10:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946499#M370659</link>
      <description>&lt;P&gt;Thans for your answer.&lt;BR /&gt;I like it and it all works.&lt;BR /&gt;But I am still a beginner and the original file(Eems_Dollard.csv) had a starting column called "Zoekopdracht".&lt;BR /&gt;When i apply your answer to the original file it does not work and I do not know why.&lt;BR /&gt;If you succeed I would like to hear from you.&lt;BR /&gt;Thanks again for the effort.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 10:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946499#M370659</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-10-07T10:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946502#M370660</link>
      <description>&lt;P&gt;Thank you for your answer.&lt;BR /&gt;I like it and it all works.&lt;BR /&gt;When i apply your answer to the original file it does not work and I do not know why.&lt;BR /&gt;If you succeed I would like to hear from you.&lt;BR /&gt;Thanks again for the effort.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 10:56:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946502#M370660</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-10-07T10:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946517#M370662</link>
      <description>&lt;P&gt;Where are you getting these files?&amp;nbsp; Perhaps you should talk to the providers and get them to clarify what type of files they are producing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you look at the first few bytes of that file:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  infile "C:\downloads\Eems_Dollard.csv" lrecl=100 recfm=f obs=5;
  input;
  list;
run;&lt;/PRE&gt;
&lt;P&gt;It seems to be using LF only as the end of line marker.&amp;nbsp; Which means that if there are ANY other embedded LF characters (like you had in the other file) then there is no way for SAS to tell the difference between a real END OF LINE marker and these other LF characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try seeing if the extra LF characters are at least nested inside of double quotes by running this macro,&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/replace_crlf.sas" target="_self"&gt;%replace_crlf&lt;/A&gt;&amp;nbsp; ,to make a new version of the file where such embedded LF (and or CR) characters are either removed or replaced with some other character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That seems to work fine for the supplied file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv "C:\downloads\Eems_Dollard.csv";
filename csv2 temp;
%replace_crlf(csv,csv2,lf=' ',cr=)
%csv2ds(csv2,dlm=';',out=want,replace=YES)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Making a file that can be read by SAS.&lt;/P&gt;
&lt;PRE&gt;5   +data want;
6   +  infile CSV2 dlm=';' dsd truncover firstobs=2 ;
7   +  length Zoekopdracht $34 Datum 8 Url $341 Sentiment $8 Type $7
8   +    Discussie_lengte 8 Views 8 Auteur $81 Volgers 8 Bron $9 Titel $172
9   +    Bericht $9010 Labels $1
10  +  ;
11  +  informat Datum anydtdtm. ;
12  +  format Datum datetime19. ;
13  +  label Discussie_lengte='Discussie lengte' ;
14  +  input Zoekopdracht -- Labels ;
15  +run;

NOTE: The infile CSV2 is:
      (system-specific pathname),
      (system-specific file attributes)

NOTE: 2124 records were read from the infile (system-specific pathname).
      The minimum record length was 175.
      The maximum record length was 9208.
NOTE: The data set WORK.WANT has 2124 observations and 13 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 16:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946517#M370662</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-07T16:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946538#M370669</link>
      <description>&lt;P&gt;You have an additional column in this file , here's the revised code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;infile "c:\temp\Eems_Dollard.csv" dlm=';' dsd missover firstobs=2;&lt;BR /&gt;input Zoekopdracht : $ 200. Datnum : $15. Url : $100. Sentiment : $10. Type : $10.&lt;BR /&gt;Discussie_Lengte : 8. Views : 8. Auteur : $25. Volgers : 8.&lt;BR /&gt;Bron : $15. Title : $200. Bericht : $300. Labels : $10.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print data=test;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 14:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946538#M370669</guid>
      <dc:creator>JOL</dc:creator>
      <dc:date>2024-10-07T14:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946550#M370674</link>
      <description>&lt;P&gt;Thanks for your quick reply.&lt;BR /&gt;As I said I am still a beginner so it will be hard enough for me.&lt;BR /&gt;But I have already learned something from you so thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 16:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946550#M370674</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-10-07T16:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: import a crazy csv file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946560#M370682</link>
      <description>&lt;P&gt;Thanks for your quick reply.&lt;BR /&gt;But it doesn't work completely, look at the screen shot(in pdf formaat).&lt;BR /&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 16:38:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/import-a-crazy-csv-file/m-p/946560#M370682</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-10-07T16:38:48Z</dc:date>
    </item>
  </channel>
</rss>

