BookmarkSubscribeRSS Feed
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.



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;

proc import file=csv dbms=csv out=want replace;

proc contents data=want noprint out=contents; run;

data _null_;
  set contents;
  put (varnum namelen name label) (=);
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
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;
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. 





Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3 in conversation