<?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: How to automate changing the encoding of a csv file from UTF-8 to ASCII in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675161#M203384</link>
    <description>&lt;P&gt;Here is a sample of the data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.SESSIONS;
  infile datalines dsd truncover;
  input SessionId:BEST12. OrgId:BEST12. UserId:BEST12. DateStarted:B8601DZ35. DateEnded:B8601DZ35. LastAccessed:B8601DZ35. TimedOut:$5. HistoryId:BEST12.;
  format SessionId BEST12. OrgId BEST12. UserId BEST12. DateStarted B8601DZ35. DateEnded B8601DZ35. LastAccessed B8601DZ35. HistoryId BEST12.;
datalines;
7470839 6606 28324 20200803T045055+0000 20200803T045118+0000 20200803T045118+0000 False 7602172
7468717 6606 . 20200803T014715+0000 20200803T044906+0000 20200803T014715+0000 True 7602171
7468085 6606 8586 20200803T005353+0000 20200803T044906+0000 20200803T014445+0000 True 7602170
7468727 6606 . 20200803T014746+0000 20200803T044906+0000 20200803T014746+0000 True 7602169
7468635 6606 27937 20200803T014043+0000 20200803T044906+0000 20200803T014043+0000 True 7602168
7468651 6606 . 20200803T014221+0000 20200803T044906+0000 20200803T014221+0000 True 7602167
7468630 6606 . 20200803T014023+0000 20200803T044906+0000 20200803T014023+0000 True 7602166
7468708 6606 7004 20200803T014653+0000 20200803T044906+0000 20200803T014706+0000 True 7602165
7468733 6606 . 20200803T014752+0000 20200803T044906+0000 20200803T014752+0000 True 7602164
7468673 6606 22851 20200803T014337+0000 20200803T044906+0000 20200803T014337+0000 True 7602163
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Jeff&lt;/P&gt;</description>
    <pubDate>Thu, 06 Aug 2020 23:00:03 GMT</pubDate>
    <dc:creator>jmartin-moreno</dc:creator>
    <dc:date>2020-08-06T23:00:03Z</dc:date>
    <item>
      <title>How to automate changing the encoding of a csv file from UTF-8 to ASCII</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675158#M203382</link>
      <description>&lt;P&gt;I am working in SAS Enterprise Guide 7.1 with csv files exported from a higher education learning management system (LMS). The files are encoded as UTF-8.&amp;nbsp; When I import them using a data step, they appear to import fine, but only the first 350,000 lines of data are imported.&amp;nbsp; I read in another thread that this was likely an encoding issue. I took the suggestion there to open the files in Notepad, then in the Save As dialog, change the encoding from UTF-8 to ANSII. That works. Once the files are encoded as ASCII, all the data lines import to SAS just fine.&amp;nbsp; I need to be able to automate this process so I don't have to open each file and save them with the new encoding. Does anyone know of a way either in SAS Enterprise Guide 7.1, Base SAS, or using a bat file to automate this task? I am using a data step to import the data to SAS EG. I have also tried PROC IMPORT with an encoding statement that has not yielded the results I was looking for. Here is my data step code, which only imported the first 350,000 rows of data:&lt;/P&gt;&lt;PRE&gt;DATA WORK.Sessions; 
    INFILE "\\MCC-HOMES\IEDATA\IR_DATA\Brightspace\DATA\SessionHistory_ascii.csv" 
        DLM=',' 
    	MISSOVER 
		FIRSTOBS=2 
    	DSD; 
    LENGTH
        SessionId        $ 7
        OrgId            $ 4
        UserId           $ 5
        DateStarted        8
        DateEnded          8
        LastAccessed       8
        TimedOut         $ 5
        HistoryId        $ 7 ;
    FORMAT
        SessionId        $CHAR7.
        OrgId            $CHAR4.
        UserId           $CHAR5.
        DateStarted      DATETIME21.2
        DateEnded        DATETIME21.2
        LastAccessed     DATETIME21.2
        TimedOut         $CHAR5.
        HistoryId        $CHAR7. ;
    INPUT
        SessionId        : $CHAR7.
        OrgId            : $CHAR4.
        UserId           : $CHAR5.
        DateStarted      : ?? ANYDTDTM28.
        DateEnded        : ?? ANYDTDTM28.
        LastAccessed     : ?? ANYDTDTM28.
        TimedOut         : $CHAR5.
        HistoryId        : $CHAR7. ;
RUN;&lt;/PRE&gt;&lt;P&gt;Below are three attempts I tried using PROC IMPORT.&amp;nbsp; I didn't get any error messages but the also only imported the first 350k lines.&lt;/P&gt;&lt;PRE&gt;/*	-----------------------------------------------
	FIRST PROC IMPORT ATTEMPT AT PROC IMPORT
	THIS INPORTED ONLY THE FIRST 350,000 DATA ROWS 
	------------------------------------------------ */
proc import datafile = "\\MCC-HOMES\IEDATA\IR_DATA\Brightspace\DATA\SessionHistory.csv"

 out  = WORK.SESSIONS
 dbms  =  csv
 replace;

run;

/*	----------------------------------------------
	SECOND PROC IMPORT ATTEMPT AT PROC IMPORT
	THIS INPORTED ONLY THE FIRST 350,000 DATA ROWS 
	---------------------------------------------- */
filename temp "\\MCC-HOMES\IEDATA\IR_DATA\Brightspace\DATA\SessionHistory.csv" encoding="utf-8";

proc import datafile = temp
 out  = utf8
 dbms  =  csv
 replace;
run;

/*	--------------------------------------------------------------------------------
	THIRD PROC IMPORT ATTEMPT
	THIS INPORTED ONLY THE FIRST 350,000 DATA ROWS 
	-------------------------------------------------------------------------------- */
filename temp "\\MCC-HOMES\IEDATA\IR_DATA\Brightspace\DATA\SessionHistory.csv" encoding="utf-8" lrecl=32767;

   proc import datafile=temp out=sessions dbms=csv replace;
   run;&lt;/PRE&gt;&lt;P&gt;Thanks in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jeff&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 22:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675158#M203382</guid>
      <dc:creator>jmartin-moreno</dc:creator>
      <dc:date>2020-08-06T22:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate changing the encoding of a csv file from UTF-8 to ASCII</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675161#M203384</link>
      <description>&lt;P&gt;Here is a sample of the data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.SESSIONS;
  infile datalines dsd truncover;
  input SessionId:BEST12. OrgId:BEST12. UserId:BEST12. DateStarted:B8601DZ35. DateEnded:B8601DZ35. LastAccessed:B8601DZ35. TimedOut:$5. HistoryId:BEST12.;
  format SessionId BEST12. OrgId BEST12. UserId BEST12. DateStarted B8601DZ35. DateEnded B8601DZ35. LastAccessed B8601DZ35. HistoryId BEST12.;
datalines;
7470839 6606 28324 20200803T045055+0000 20200803T045118+0000 20200803T045118+0000 False 7602172
7468717 6606 . 20200803T014715+0000 20200803T044906+0000 20200803T014715+0000 True 7602171
7468085 6606 8586 20200803T005353+0000 20200803T044906+0000 20200803T014445+0000 True 7602170
7468727 6606 . 20200803T014746+0000 20200803T044906+0000 20200803T014746+0000 True 7602169
7468635 6606 27937 20200803T014043+0000 20200803T044906+0000 20200803T014043+0000 True 7602168
7468651 6606 . 20200803T014221+0000 20200803T044906+0000 20200803T014221+0000 True 7602167
7468630 6606 . 20200803T014023+0000 20200803T044906+0000 20200803T014023+0000 True 7602166
7468708 6606 7004 20200803T014653+0000 20200803T044906+0000 20200803T014706+0000 True 7602165
7468733 6606 . 20200803T014752+0000 20200803T044906+0000 20200803T014752+0000 True 7602164
7468673 6606 22851 20200803T014337+0000 20200803T044906+0000 20200803T014337+0000 True 7602163
;;;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Jeff&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 23:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675161#M203384</guid>
      <dc:creator>jmartin-moreno</dc:creator>
      <dc:date>2020-08-06T23:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate changing the encoding of a csv file from UTF-8 to ASCII</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675165#M203388</link>
      <description>&lt;P&gt;Check your SAS session ENCODING system option using PROC OPTIONS. If it is not UTF-8 then try starting a SAS session with ENCODING='UTF-8'. Then test reading your CSV file again.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 23:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675165#M203388</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-08-06T23:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to automate changing the encoding of a csv file from UTF-8 to ASCII</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675183#M203395</link>
      <description>&lt;P&gt;Is it possible to create those files with ut8-bom instead of utf-8? With the bom sas automatically recognizes the encoding and will read the file, unless it contains char not in the ascii-table.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Aug 2020 06:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-automate-changing-the-encoding-of-a-csv-file-from-UTF-8/m-p/675183#M203395</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-07T06:21:23Z</dc:date>
    </item>
  </channel>
</rss>

