When I import a csv file, which contains a variable name with length of 34 characters, since SAS variable name can only have 32 characters, what I expected is the last 2 characters will be truncated, then the variable name in SAS dataset should be 32 characters long, however, after the import, the variable name contains 33 characters, which cause other problems, I cannot use the variable name in my program to assign this variable to another variable. Could you please advise how we should handle the problem? Thanks.
We aren't support. Just other interested SAS users.
Can you make a trivial example that demonstrates the issue? Just a few lines and a few fields per line. Post the example text using the pop-up window that opens when you click on the Insert Code button (looks like < / > ).
There is no need to use PROC IMPORT to read a CSV file. You can write your own data step to read it and then you have full control over the variable names. Personally I rarely use variable names that are longer than 8 characters as it just makes using the data harder. Longer descriptions of the meaning of a variable can be placed in the variable LABEL instead.
I cannot recreate your issue.
filename csv temp; options parmcards=csv; parmcards; id,this_name_is_longer_than_thirty_two_charaters,number abc,xyz,123 ; proc import file=csv dbms=csv out=want replace; run; proc contents data=want noprint out=contents; run; data _null_; set contents; namelen=length(name); put (varnum namelen name label) (=); run;
652 data _null_; 653 set contents; 654 namelen=length(name); 655 put (varnum namelen name label) (=); 656 run; VARNUM=1 namelen=2 NAME=id LABEL= VARNUM=3 namelen=6 NAME=number LABEL= VARNUM=2 namelen=32 NAME=this_name_is_longer_than_thirty_ LABEL= NOTE: There were 3 observations read from the data set WORK.CONTENTS. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 seconds
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.