<?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: Editing text with long record length in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937184#M368246</link>
    <description>&lt;P&gt;Thanks. I guess I'll have to try this approach (even if a bit messy). Thanks for investigating.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jul 2024 04:14:22 GMT</pubDate>
    <dc:creator>BruceBrad</dc:creator>
    <dc:date>2024-07-26T04:14:22Z</dc:date>
    <item>
      <title>Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937177#M368241</link>
      <description>&lt;P&gt;I have a CSV file where the first record is very long because of long variable names (about 60k). I want to read the file in, edit the first line (eg replace all occurences of "longword" with "lw"), save the file, then read it in as per a normal CSV file. Because the record length is over 32k, I can't use the _infile_ method. Any suggestions for the best way to do this in SAS? (I'm using 9.4 on windows).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I could use some Windows batch/power script, but would prefer the portability of keeping it in SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 00:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937177#M368241</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2024-07-26T00:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937180#M368242</link>
      <description>It would be better if you post this CSV file. &lt;BR /&gt;You could try option LRECL=1000000000000  of INFILE to break the limit of 32K.</description>
      <pubDate>Fri, 26 Jul 2024 01:22:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937180#M368242</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-07-26T01:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937181#M368243</link>
      <description>&lt;P&gt;I've attached the first few records of the file (Excel can open it). The lrecl option doesn't work because I'm editing the _infile_ variable which has a fixed upper length of 32K.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 02:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937181#M368243</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2024-07-26T02:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937182#M368244</link>
      <description>&lt;P&gt;You could import this csv file into sas firstly, afterwards change variable name by data step ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename x 'c:\temp\LongRecordTest.csv' lrecl=1000000 encoding='utf8' termstr=crlf;

proc import datafile=x out=have dbms=csv replace;
run;



proc transpose data=have(obs=0) out=temp;
var _all_;
run;
data temp;
 set temp;
if find(_NAME_,'Lonemother') then do; new_name=tranwrd(_NAME_,'Lonemother','LO');output;end;
run;
data _null_;
 set temp end=last;
if _n_=1 then call execute('proc datasets library=work nolist nodetails;modify have;rename ');
call execute(catx('=',_name_,new_name));
if last then call execute(';quit;');
run;
&lt;/CODE&gt;&lt;/PRE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 03:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937182#M368244</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-07-26T03:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937184#M368246</link>
      <description>&lt;P&gt;Thanks. I guess I'll have to try this approach (even if a bit messy). Thanks for investigating.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 04:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937184#M368246</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2024-07-26T04:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937195#M368247</link>
      <description>&lt;P&gt;OK. It looks like your problem is not so easy. Try this one :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options compress=yes;
data have;
infile 'c:\temp\LongRecordTest.csv' dsd truncover lrecl=1000000 encoding='utf8' termstr=crlf;
input (__v1-__v2000) (:$200.);
run;
proc transpose data=have(obs=1) out=rename;
var _all_;
run;
data rename2;
 set rename(where=(col1 is not missing));
 new_name=tranwrd(col1,'Lonemother','LO');
 new_name=tranwrd(new_name,'Twoparent','TP');
 if length(new_name)&amp;gt;32 then new_name=substr(new_name,1,32);
run;
data _null_;
 set rename2 end=last;
if _n_=1 then call execute('proc datasets library=work nolist nodetails;modify have;rename ');
call execute(catx('=',_name_,new_name));
if last then call execute(';quit;');
run;
data want;
 set have(firstobs=2);
 drop __v:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2024 07:07:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937195#M368247</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-07-26T07:07:33Z</dc:date>
    </item>
    <item>
      <title>Re: Editing text with long record length</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937249#M368262</link>
      <description>&lt;P&gt;Since when you read a CSV file into data you SKIP the header line I do not see why reading that should cause any trouble.&amp;nbsp; The data lines are less than 12K bytes long.&lt;/P&gt;
&lt;PRE&gt;NOTE: 2 records were read from the infile (system-specific pathname).
      The minimum record length was 10232.
      The maximum record length was 11811.
&lt;/PRE&gt;
&lt;P&gt;Are you trying to use PROC IMPORT to make guesses about how to read the file?&amp;nbsp; Why ?&amp;nbsp; It looks like all of the variables are NUMERIC, except for the first one.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile 'myfile.csv' dsd firstob=2 truncover;
  input lisacronym :$10. var2-var1216 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then read in the header row and use that to generate labels for your variables.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data names ;
  infile "myfile.csv" dsd lrecl=1000000 obs=1 ;
  varnum+1;
  input label :$256. @@;
  if varnum=1 then put 'label ' ;
  else put 'var' varnum '=' label :$quote. ;
run;
proc datasets nolist lib=work;
modify want;
%include code ;
;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do want to use something to GUESS how to read the file then use this macro instead.&amp;nbsp; It will both read the long header row properly and also create unique variable names for the variables whose labels are not unique in the first 32 bytes.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv "C:\downloads\LongRecordTest.csv" lrecl=1000000;
%csv2ds(csv,out=want,replace=1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: The %CSV2DS() macro will make empty variables character of length 1 just like PROC IMPORT.&amp;nbsp; But you can use the OVERRRIDES= option to give it a dataset to force it make those columns numeric if you want.&amp;nbsp; So you could add this code to make the over ride information from the _TYPES_ dataset it generated and re-run the macro passing in that those overrides.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data overrides;
  set _types_;
  where xtype='empty';
  type='num';length='8';
  keep varnum type length;
run;
%csv2ds(csv,out=want,overrides=overrides,replace=1);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jul 2024 13:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Editing-text-with-long-record-length/m-p/937249#M368262</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-26T13:54:38Z</dc:date>
    </item>
  </channel>
</rss>

