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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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