<?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 read zip-files from windows in linux encoding problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721842#M223774</link>
    <description>&lt;P&gt;I will import an xlsx file from an zip-file created in windows to a Viya/Linux environment. I am folowing&amp;nbsp;Chris Hemedingers excelent blog,&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-sas/" target="_blank"&gt;Using FILENAME ZIP to unzip and read data files in SAS - The SAS Dummy&lt;/A&gt;, and it works perfect when I using my windows installation on workstation. The same code does not work in SAS Studio on Viya.&lt;/P&gt;
&lt;P&gt;The obvious prolem is the files within the zip-file uses character åäö. I tried to use the options encoding="wlatin1" in the filename statement, but Viya ignore it, or I have done it in the wrong way.&lt;/P&gt;
&lt;P&gt;There was another problem, "filename" does not accept path with spaces such as "Region Skåne konkurser".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename inzip ZIP "/opt/sas/spre/config/samhallsdata/indata/RegionSkaneKonkurser/dia_konkurser_v1_2020_v6_2021.zip" encoding='wlatin1';
run;
data contents(keep=memname isFolder);
	length memname $200 isFolder 8;
	fid=dopen("inzip");
	if fid=0 then stop;
	memcount=dnum(fid);
	do i=1 to memcount;
		memname = dread(fid,i);
		isFolder = (first(reverse(trim(memname)))='/');
		output;
	end;
	rc=dclose(fid);
run;
title "Files in the ZIP file";
proc print data=contents noobs N;
run;
title;
run;
filename xlClan "%sysfunc(getoption(work))/dataunderlag_konkurser_Uppsala lan.xlsx";

data _null_;
	infile inzip(dia_konkurser/dia_konk_Uppsala län/dataunderlag_konkurser_Uppsala län.xlsx)
		lrecl=256 recfm=F length=length eof=eof unbuf;
	file xlClan lrecl=256 recfm=N;
	input;
	put _infile_ $varying256. length;
	return;
eof:
	stop;
run;

proc import datafile=xlClan out=confirmed replace dbms=xlsx;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 25 Feb 2021 12:58:47 GMT</pubDate>
    <dc:creator>AndersBergquist</dc:creator>
    <dc:date>2021-02-25T12:58:47Z</dc:date>
    <item>
      <title>read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721842#M223774</link>
      <description>&lt;P&gt;I will import an xlsx file from an zip-file created in windows to a Viya/Linux environment. I am folowing&amp;nbsp;Chris Hemedingers excelent blog,&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-sas/" target="_blank"&gt;Using FILENAME ZIP to unzip and read data files in SAS - The SAS Dummy&lt;/A&gt;, and it works perfect when I using my windows installation on workstation. The same code does not work in SAS Studio on Viya.&lt;/P&gt;
&lt;P&gt;The obvious prolem is the files within the zip-file uses character åäö. I tried to use the options encoding="wlatin1" in the filename statement, but Viya ignore it, or I have done it in the wrong way.&lt;/P&gt;
&lt;P&gt;There was another problem, "filename" does not accept path with spaces such as "Region Skåne konkurser".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename inzip ZIP "/opt/sas/spre/config/samhallsdata/indata/RegionSkaneKonkurser/dia_konkurser_v1_2020_v6_2021.zip" encoding='wlatin1';
run;
data contents(keep=memname isFolder);
	length memname $200 isFolder 8;
	fid=dopen("inzip");
	if fid=0 then stop;
	memcount=dnum(fid);
	do i=1 to memcount;
		memname = dread(fid,i);
		isFolder = (first(reverse(trim(memname)))='/');
		output;
	end;
	rc=dclose(fid);
run;
title "Files in the ZIP file";
proc print data=contents noobs N;
run;
title;
run;
filename xlClan "%sysfunc(getoption(work))/dataunderlag_konkurser_Uppsala lan.xlsx";

data _null_;
	infile inzip(dia_konkurser/dia_konk_Uppsala län/dataunderlag_konkurser_Uppsala län.xlsx)
		lrecl=256 recfm=F length=length eof=eof unbuf;
	file xlClan lrecl=256 recfm=N;
	input;
	put _infile_ $varying256. length;
	return;
eof:
	stop;
run;

proc import datafile=xlClan out=confirmed replace dbms=xlsx;
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 12:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721842#M223774</guid>
      <dc:creator>AndersBergquist</dc:creator>
      <dc:date>2021-02-25T12:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721861#M223784</link>
      <description>&lt;P&gt;I don't think the ENCODING option would apply to FILENAME ZIP method, as it's a binary file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your SAS session running using ENCODING='utf-8'?&amp;nbsp; Actually, I think that's the default in SAS Viya anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always recommend that -- I believe that the innards of Excel files (xlsx) are UTF-8 encoded, and UTF-8 allows the most flexibility for managing character content.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 13:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721861#M223784</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-02-25T13:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721872#M223788</link>
      <description>My problem is that SAS read the ZIP content directory as utf-8, even if it is wlatin1, But maybe You point me to the rigth directions.&lt;BR /&gt;Do You think it will work if I change the two first lines in the first datastep to&lt;BR /&gt;data work.contents(encoding='wlatin1');&lt;BR /&gt;	keep memname isFolder;</description>
      <pubDate>Thu, 25 Feb 2021 14:11:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721872#M223788</guid>
      <dc:creator>AndersBergquist</dc:creator>
      <dc:date>2021-02-25T14:11:05Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721875#M223789</link>
      <description>No, it does not work. Error.&lt;BR /&gt;There is aproblem then SAS reads the content of zip-files with non US-characters.</description>
      <pubDate>Thu, 25 Feb 2021 14:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721875#M223789</guid>
      <dc:creator>AndersBergquist</dc:creator>
      <dc:date>2021-02-25T14:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721885#M223791</link>
      <description>&lt;P&gt;I have made a little test-file with one file named åäö.txt.&lt;/P&gt;
&lt;P&gt;Here is the code.&lt;/P&gt;
&lt;PRE&gt;filename yxzip ZIP "/opt/sas/spre/config/samhallsdata/indata/RegionSkaneKonkurser/testdoc.zip";
run;
data work.contents(encoding='wlatin1');
	keep memname isFolder;
	length memname $200 isFolder 8;
	fid=dopen("yxzip");
	if fid=0 then stop;
	memcount=dnum(fid);
put memcount=;
	do i=1 to memcount;
put i=;
		memname = dread(fid,i);
put memname=;
		isFolder = (first(reverse(trim(memname)))='/');
		output;
	end;
	rc=dclose(fid);
run;
title "Files in the ZIP file";
proc print data=contents noobs N;
run;
title;&lt;/PRE&gt;
&lt;P&gt;And i got this log&lt;/P&gt;
&lt;PRE&gt;82   
83   data work.contents(encoding='wlatin1');
84   keep memname isFolder;
85   length memname $200 isFolder 8;
86   fid=dopen("yxzip");
87   if fid=0 then stop;
88   memcount=dnum(fid);
89   put memcount=;
90   do i=1 to memcount;
91   put i=;
92   memname = dread(fid,i);
93   put memname=;
94   isFolder = (first(reverse(trim(memname)))='/');
95   output;
96   end;
97   rc=dclose(fid);
98   run;
NOTE: Data file WORK.CONTENTS.DATA is in a format that is native to another host, or the file encoding does not match the session 
      encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce 
      performance.
memcount=2
i=1
memname=testdoc.sas
i=2
memname=���.txt
ERROR: Some character data was lost during transcoding in the dataset WORK.CONTENTS. Either the data contains characters that are 
       not representable in the new encoding or truncation occurred during transcoding.
NOTE: The DATA step has been abnormally terminated.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CONTENTS may be incomplete.  When this step was stopped there were 1 observations and 2 variables.
WARNING: Data set WORK.CONTENTS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 14:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721885#M223791</guid>
      <dc:creator>AndersBergquist</dc:creator>
      <dc:date>2021-02-25T14:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721907#M223799</link>
      <description>&lt;P&gt;Just found the NAMEENCODING option that might be useful:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsglobal&amp;amp;docsetTarget=n1dn0f61yfyzton1l2ngsa1clllr.htm&amp;amp;locale=en" target="_self"&gt;Doc here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4 class="xisDoc-argument"&gt;NAMEENCODING=&lt;EM class="xisDoc-userSuppliedValue"&gt;encoding-value&lt;/EM&gt;&lt;/H4&gt;
&lt;DIV class="xisDoc-argumentDescription"&gt;
&lt;P class="xisDoc-paraSimpleFirst"&gt;specifies the encoding to use for ZIP file entry names and comments. The value for NAMEENCODING= indicates that the entry name and comment have a different encoding from the current session encoding.&lt;/P&gt;
&lt;SECTION class="xisDoc-tableWrap"&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="xisDoc-summaryDefault"&gt;Default&lt;/TH&gt;
&lt;TD class="xisDoc-summaryText"&gt;Code Page 437&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="xisDoc-summaryExample"&gt;Example&lt;/TH&gt;
&lt;TD class="xisDoc-summaryText"&gt;
&lt;PRE class="xisDoc-codeFragmentOnly"&gt;&lt;CODE&gt;filename zs zip "yxz.zip" nameencoding=sjis member="s" termstr=lf;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/nlsref/n1r7pnb91iybs9n1hgvsj7q09srd.htm?homeOnFail" target="_self"&gt;SAS documentation for a reference table of available encodings&lt;/A&gt;.&lt;/P&gt;
&lt;/SECTION&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 08 Nov 2021 13:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721907#M223799</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-11-08T13:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721927#M223803</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;NAMEENCODING="Cp437"&lt;/P&gt;
&lt;P&gt;make it.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 17:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/721927#M223803</guid>
      <dc:creator>AndersBergquist</dc:creator>
      <dc:date>2021-02-25T17:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/779069#M248092</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;What other nameenciding values are available? List somewhere?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 08:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/779069#M248092</guid>
      <dc:creator>HannuSihvonen</dc:creator>
      <dc:date>2021-11-08T08:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: read zip-files from windows in linux encoding problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/779110#M248109</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/325008"&gt;@HannuSihvonen&lt;/a&gt;&amp;nbsp;There is a &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/nlsref/n1r7pnb91iybs9n1hgvsj7q09srd.htm?homeOnFail" target="_self"&gt;reference table in the SAS documentation&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 13:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-zip-files-from-windows-in-linux-encoding-problem/m-p/779110#M248109</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-11-08T13:12:37Z</dc:date>
    </item>
  </channel>
</rss>

