<?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: is varchar supposed to work with scan function? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844118#M333725</link>
    <description>&lt;P&gt;.tsv is a tab-delimited file, yes. According to &lt;A href="https://luminaredata.com/wp-content/uploads/2018/04/Using_SAS_94M5_to_Manage_Strings_Exceeding_32kb.pdf" target="_blank"&gt;https://luminaredata.com/wp-content/uploads/2018/04/Using_SAS_94M5_to_Manage_Strings_Exceeding_32kb.pdf&lt;/A&gt; there is limited support for varchar in the data step. I am trying to split the string into pieces shorter than 32k before saving it, but it appears not to work.&lt;/P&gt;&lt;P&gt;I cannot share my code 1:1 as the data are proprietary but I will see if I can come up with an example.&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2022 14:16:15 GMT</pubDate>
    <dc:creator>js5</dc:creator>
    <dc:date>2022-11-14T14:16:15Z</dc:date>
    <item>
      <title>is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844085#M333720</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a .tsv file with variables exceeding 32767 characters. I have managed to read these using input statement and varchar(131071) data type and lrecl=262143, but when I try to split the long variables into several pieces using scan, processing ends at character 32767. Is this supposed to be working?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 12:30:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844085#M333720</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-11-14T12:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844109#M333722</link>
      <description>&lt;P&gt;I think it should work, but don't have SAS Viya at my fingertips.&lt;/P&gt;
&lt;P&gt;Can you show the log from the import and scan operations?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 13:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844109#M333722</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-11-14T13:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844110#M333723</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223838"&gt;@js5&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a .tsv file with variables exceeding 32767 characters. I have managed to read these using input statement and varchar(131071) data type and lrecl=262143, but when I try to split the long variables into several pieces using scan, processing ends at character 32767. Is this supposed to be working?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please show the code you are using.&lt;/P&gt;
&lt;P&gt;A SAS dataset only has two types of variables, floating point numbers and fixed length character strings.&amp;nbsp; The maximum length of a character string is 32,767 bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you using something other than a SAS data step to read the file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is a TSV file?&amp;nbsp; Do you mean a tab delimited text file?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 13:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844110#M333723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-14T13:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844116#M333724</link>
      <description>Since OP refers to varchar I guess this is executed in CAS.</description>
      <pubDate>Mon, 14 Nov 2022 14:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844116#M333724</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-11-14T14:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844118#M333725</link>
      <description>&lt;P&gt;.tsv is a tab-delimited file, yes. According to &lt;A href="https://luminaredata.com/wp-content/uploads/2018/04/Using_SAS_94M5_to_Manage_Strings_Exceeding_32kb.pdf" target="_blank"&gt;https://luminaredata.com/wp-content/uploads/2018/04/Using_SAS_94M5_to_Manage_Strings_Exceeding_32kb.pdf&lt;/A&gt; there is limited support for varchar in the data step. I am trying to split the string into pieces shorter than 32k before saving it, but it appears not to work.&lt;/P&gt;&lt;P&gt;I cannot share my code 1:1 as the data are proprietary but I will see if I can come up with an example.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:16:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844118#M333725</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-11-14T14:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844119#M333726</link>
      <description>&lt;P&gt;I think it should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I played&amp;nbsp; bit in Base SAS 9.4M7.&amp;nbsp; It looks like SCAN worked okay for this test.&amp;nbsp; But I did have a problem with REPEAT not wanting to write a string longer than 32,767.&amp;nbsp; Since VARCHAR is new to DATA step (M5 I think), it wouldn't be that surprising if some functions don't handle it correctly yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data _null_ ;
2      length longstr varchar(40000) longstr2 varchar(80000);
3      longstr=repeat('abc ',9999) ;
4      l=length(longstr) ; *I think this should be 40000, but its only 32767 ;
5
6
7      longstr2=trim(longstr)||longstr ;
8
9      longstr2=trim(longstr2)||' def' ;
10
11     l2=length(longstr2) ;
12     lastword=scan(longstr2,-1) ;
13     put l= l2= lastword= ;
14   run;

l=32767 l2=65538 lastword=def
&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844119#M333726</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-14T14:23:40Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844120#M333727</link>
      <description>&lt;P&gt;You can read a text file with strings that are longer than 32K, you just have to read them into multiple variables (or multiple observations).&amp;nbsp; You can use the COLUMN= option of the INFILE statement to help you understand the length of the fields on the line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like this in normal SAS code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile TSV dsd dlm='09'x truncover firstobs=2 column=cc ;
  length id slen 8 str1-str5 $32767 ;
  array str str1-str5;
  input id @ ;
  start=cc;
  input str1 @ ;
  end=cc;
  slen=end-start+1;
  input @start ;
  do index=1 to ceil(slen/32767);
    input str[index] $char32767. ;
    if 32767*(index-1) &amp;gt; slen then do;
      str[index]=substrn(str[index],1,32767*(index-1)-slen);
    end;
  end;
run;
  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844120#M333727</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-14T14:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844127#M333728</link>
      <description>&lt;P&gt;CAS i required if you want to persist VARCHAR variables in your output dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="xisDoc-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="xisDoc-requirement"&gt;Requirement&lt;/TH&gt;
&lt;TD class="xisDoc-summaryText"&gt;The CAS engine is required if you want to preserve a variable as a VARCHAR data type when reading it in or writing it out using the DATA step.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844127#M333728</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2022-11-14T14:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844131#M333729</link>
      <description>&lt;P&gt;I do not need the varchar variables in my output dataset, I am dropping them. I only need to read the long strings into varchars so that I can split them into &amp;lt;32k pieces with scan before outputting them to an output dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 14:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844131#M333729</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-11-14T14:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844138#M333730</link>
      <description>&lt;P&gt;Can you make a small example, like the data step I posted, that shows the problem?&amp;nbsp; It looked like scan worked for me.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 15:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844138#M333730</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-14T15:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844140#M333731</link>
      <description>&lt;P&gt;This seems to be sufficient to reproduce the problem:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data varchar;
	infile "C:\users\&amp;amp;sysuserid\Work Folders\Desktop\SAS\varchar\input.txt" truncover dsd delimiter='09'x lrecl=100000;
	length var1 varchar(70000) var2 $10;
	input var1 var2;

	do i = 1 to countw(var1, " ");
		short = scan(var1, i, " ");
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Neither countw nor scan seem to work beyond 32727 characters.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 15:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844140#M333731</guid>
      <dc:creator>js5</dc:creator>
      <dc:date>2022-11-14T15:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: is varchar supposed to work with scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844168#M333735</link>
      <description>&lt;P&gt;I think the problem is actually before that.&amp;nbsp; It looks like when you INPUT the data, it's only grabbing the first 32,767 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think to make this work, you would need to find an informat to use on the INPUT statement that allows a length &amp;gt;32767.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From a quick read of the docs, I don't see any.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data _null_;
2      infile "Q:\junk\input.txt" truncover dsd delimiter='09'x lrecl=100000;
3      length var1 varchar(70000) var2 $10;
4      input var1 var2;
5
6      l=length(var1) ;
7      put l= ;
8    run;

NOTE: The infile "Q:\junk\input.txt" is:
      Filename=Q:\junk\input.txt,
      RECFM=V,LRECL=100000,File Size (bytes)=60012,
      Last Modified=14Nov2022:11:41:23,
      Create Time=14Nov2022:11:41:23

l=32767
NOTE: 1 record was read from the infile "Q:\junk\input.txt".
      The minimum record length was 60010.
      The maximum record length was 60010.
&lt;/PRE&gt;
&lt;P&gt;If you can't find an informat that will read &amp;gt; 32,767 characters, you might have to read it in chunks, as Tom suggested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 17:03:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-varchar-supposed-to-work-with-scan-function/m-p/844168#M333735</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-14T17:03:55Z</dc:date>
    </item>
  </channel>
</rss>

