<?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 Import csv: Number of names found is less than number of variables found in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803059#M316208</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I import 2 csv files which has 3879 columns with column name format: AAAAAAA:BBBBB. SAS successfully imported both files BUT for 1 file, SAS gets the correct name for just a part of it. Hundreds of columns at the end have name of VAR_:&lt;/P&gt;
&lt;P&gt;The notice shows in log is: "Number of names found is less than number of variables found."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enclosed is my files and the SAS log for the problem file.&lt;/P&gt;
&lt;P&gt;ROE_FQ12022.csv is NOT imported correctly.&lt;/P&gt;
&lt;P&gt;Second_ROE_FQ12022.csv is imported correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help to fix it?&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file 		=ROE_FQ12022;

proc import 
datafile="\&amp;amp;FILE..csv"
out=input DBMS= csv replace; 
DATAROW=3;
getnames= yes;
run;

proc import 
datafile="\Second_&amp;amp;FILE..csv"
out=input DBMS= csv replace; 
DATAROW=3;
getnames= yes;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2022 11:49:01 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2022-03-21T11:49:01Z</dc:date>
    <item>
      <title>Import csv: Number of names found is less than number of variables found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803059#M316208</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I import 2 csv files which has 3879 columns with column name format: AAAAAAA:BBBBB. SAS successfully imported both files BUT for 1 file, SAS gets the correct name for just a part of it. Hundreds of columns at the end have name of VAR_:&lt;/P&gt;
&lt;P&gt;The notice shows in log is: "Number of names found is less than number of variables found."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enclosed is my files and the SAS log for the problem file.&lt;/P&gt;
&lt;P&gt;ROE_FQ12022.csv is NOT imported correctly.&lt;/P&gt;
&lt;P&gt;Second_ROE_FQ12022.csv is imported correctly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please help to fix it?&lt;/P&gt;
&lt;P&gt;Many thanks.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file 		=ROE_FQ12022;

proc import 
datafile="\&amp;amp;FILE..csv"
out=input DBMS= csv replace; 
DATAROW=3;
getnames= yes;
run;

proc import 
datafile="\Second_&amp;amp;FILE..csv"
out=input DBMS= csv replace; 
DATAROW=3;
getnames= yes;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 11:49:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803059#M316208</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-03-21T11:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv: Number of names found is less than number of variables found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803064#M316212</link>
      <description>&lt;P&gt;Do it with data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename f1 "..\..\..\ROE_FQ12022.csv";

data test;
  infile f1 lrecl=1000000 dlm=",";
  input var : $ 32. @@;
  var = cats("var",_N_,"=",translate(var,"_",":"));
  output;
  if _N_ = 3879 then stop;
run;

data _null_;
  call execute('data test2;');
  call execute('infile f1 lrecl=1000000 dlm="," firstobs=3 dsd missover;');
  call execute('input var1-var3879;');
  call execute('rename');

  do until(eof);
    set test end=eof;
    call execute(var);
  end;

  call execute('; run;');
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT:] A bit more flexible version:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename f1 "..\..\..\..\ROE_FQ12022.csv";

data test;
  infile f1 lrecl=1 recfm=N;
  input x $ char1. @@;
  length var $ 64;
  retain var;
  keep var;

  if (x in ("," '0a'x '0d'x)) then
    do;
      n+1;
      var = cats("var",n,"=",translate(var,"_",":"));
      output;
      var = "";
      if x in ('0a'x '0d'x) then stop;
    end;
  else var = cats(var, x);
run;

data _null_;
  call execute('data test2;');
  call execute('infile f1 lrecl=1000000 dlm="," firstobs=3 dsd missover;');
  call execute(cats('input var1-var',nobs,';'));
  call execute('rename');

  do until(eof);
    set test end=eof nobs=nobs;
    call execute(var);
  end;

  call execute('; run;');
  stop;
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;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 13:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803064#M316212</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-21T13:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv: Number of names found is less than number of variables found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803066#M316214</link>
      <description>&lt;P&gt;PROC IMPORT does not handle header lines that are longer than 32K bytes.&amp;nbsp; (Even if you modified your code to tell it to read more than 32K bytes from the header line.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like all of your fields are numbers so just read them as numbers.&lt;/P&gt;
&lt;P&gt;To get a list of names read the first line separately.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data names;
  infile "&amp;amp;path/&amp;amp;fname" lrecl=1000000 obs=1 dsd ;
  length old new $32 label $256 ;
  input label @@;
  old = cats('v',_n_);
  new = translate(label,'_',':');
run;

filename rename temp;
filename label temp;
data _null_;
  set names end=eof;
  file rename;
  if _n_=1 then put 'rename';
  put old '=' new ;
  if eof then put ';';
  file label;
  if _n_=1 then put 'label';
  put old '=' label :$quote.;
  if eof then put ';' ;
  if eof then call symputx('nvar',_n_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can just read the actual data as numbers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data input ;
  infile "&amp;amp;path/&amp;amp;fname" dsd truncover firstobs=3;
  input v1-v3879;
%include rename;
%include label ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 13:13:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803066#M316214</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-21T13:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv: Number of names found is less than number of variables found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803081#M316220</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;your code worked as it is for me on SASONDemand for Academics. Reproducing the code for completeness&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let file=/home/myuid/second_ROE_FQ12022.csv;
proc import 
datafile="&amp;amp;file."
out=input DBMS= csv replace; 
DATAROW=3;
getnames= yes;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The operative portion of the&amp;nbsp; log is as follows. No error as mentioned by you seen.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The infile '/home/myuid/second_ROE_FQ12022.csv' is:
       Filename=/home/myuid/second_ROE_FQ12022.csv,
       Owner Name=myuid,Group Name=oda,
       Access Permission=-rw-r--r--,
       Last Modified=21Mar2022:10:08:38,
       File Size (bytes)=166215
 
 NOTE: 110 records were read from the infile '/home/myuid/second_ROE_FQ12022.csv'.
       The minimum record length was 1298.
       The maximum record length was 1592.
 NOTE: The data set WORK.INPUT has 110 observations and 545 variables.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 14:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803081#M316220</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2022-03-21T14:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv: Number of names found is less than number of variables found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803097#M316227</link>
      <description>&lt;P&gt;Thank you, Everyone for helping!&lt;/P&gt;
&lt;P&gt;It is amazing to see how your code run SO FAST and correctly.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 15:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803097#M316227</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-03-21T15:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: Import csv: Number of names found is less than number of variables found</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803099#M316228</link>
      <description>&lt;P&gt;If you really have a CSV file with header line that is longer than 32K bytes and you actually need to GUESS how to define the variables (instead of just assuming everything is a number like in this case) then you might want to use a more flexible tool than PROC IMPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this macro instead:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 15:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-csv-Number-of-names-found-is-less-than-number-of/m-p/803099#M316228</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-21T15:14:38Z</dc:date>
    </item>
  </channel>
</rss>

