BookmarkSubscribeRSS Feed
yangx
Obsidian | Level 7

Dear Support,

 

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.

 

xiumei

3 REPLIES 3
Tom
Super User Tom
Super User

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
Reeza
Super User
I suspect it's being read in with 32 characters for the name but the label is longer. Run a proc contents on the data set and check the variable name and label.

Also, set the following so that the typical SAS naming convention will apply.

options validvarname=v7;
yangx
Obsidian | Level 7

Thanks for your reply, I have figured out where the problem is. Now proc import works as expected, the last two characters were truncated, so the variable name has 32 characters. 

Xiumei

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 602 views
  • 2 likes
  • 3 in conversation