BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

You have discovered a bug (another bug) in PROC IMPORT.  It is triggered when using VALIDVARNAME=ANY and you have two non-standard names that are not unique in the first 32 bytes.

 

You can avoid it by setting the system option VALIDVARNAME=V7 .

Here is re-producible code to demonstrate the error.

options parmcards=csv;
filename csv temp;
parmcards;
This_name_is too_long_to_be_a_NAME1,This_name_is too_long_to_be_a_NAME2
1,Albert
2,Alice
;

options validvarname=v7;
proc import datafile=csv out=v7 dbms=csv replace ;
run;
options validvarname=any;
proc import datafile=csv out=any dbms=csv replace ;
run;
options validvarname=v7;

Or you could use a smarter tool to generate the code to read the file.  Like https://github.com/sasutils/macros/blob/master/csv2ds.sas

filename csv2ds url "https://raw.githubusercontent.com/sasutils/macros/master/csv2ds.sas";
filename parmv url "https://raw.githubusercontent.com/sasutils/macros/master/parmv.sas";
%include parmv;
%include csv2ds;
%csv2ds(csv,out=csv2ds,replace=1)

Which will try to make clearer variable names and much clearer SAS code.

      Files\_TD24420_AMRAPY3WVP0VKU0_\#LN00064.
1538 +data csv2ds;
1539 +  infile CSV dlm=',' dsd truncover firstobs=2 ;
1540 +  length This_name_is_too_long_to_be_a_NA 8
1541 +    This_name_is_too_long_to_be_a__1 $6
1542 +  ;
1543 +  label
1544 +    This_name_is_too_long_to_be_a_NA='This_name_is too_long_to_be_a_NAME1'
1545 +    This_name_is_too_long_to_be_a__1='This_name_is too_long_to_be_a_NAME2'
1546 +  ;
1547 +  input This_name_is_too_long_to_be_a_NA -- This_name_is_too_long_to_be_a__1 ;
1548 +run;

NOTE: The infile CSV is:
      Filename=C:\Users\ABERNA~1\AppData\Local\Temp\1\SAS Temporary Files\_TD24420_AMRAPY3WVP0VKU0_\#LN00063,
      RECFM=V,LRECL=32767,File Size (bytes)=92,
      Last Modified=12Jul2022:13:56:15,
      Create Time=12Jul2022:13:56:15

NOTE: 2 records were read from the infile CSV.
      The minimum record length was 7.
      The maximum record length was 8.
NOTE: The data set WORK.CSV2DS has 2 observations and 2 variables.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 1682 views
  • 10 likes
  • 4 in conversation