BookmarkSubscribeRSS Feed
chinna0369
Pyrite | Level 9

Hi,

 

I am pulling a CSV file into SAS environment by using below proc import. But the file has variable names length more than 32 characters when it comes to SAS dataset after pulling by using below program all the variable names are truncated to 32 characters. Is there any way we can pull full variable name into SAS dataset? for example one of the variable name is "Checkpoint1_Startup_In-House_1_Yes_Reason"

 

proc import out=check
	datafile="/bdm/Data/all_studies_chkp_old.csv"
	dbms=csv replace;
	guessingrows=max;
run;

 

Thanks,

Adithya

4 REPLIES 4
Tom
Super User Tom
Super User

I am not sure what you are asking for.  A NAME in SAS can only be 32 bytes long.  You cannot use those long column headers in your CSV file as the variable name.  You can instead place the column headers from your CSV into the LABEL attribute of the variable.

 

PROC IMPORT is not designed to do that, but you could easily do it yourself when you write your own data step to read the CSV file.  It is always better to write your own data step to read a text file instead of using some tool to GUESS what the variables are.

 

You could re-read the first line and use it to generate a LABEL statement.  You could use PROC DATASETS to modify the labels on the dataset that PROC IMPORT created.

proc transpose data=check(obs=0) out=names ; 
  var _all_;
run;
filename labels temp;
data _null_;
  length nliteral $64 label $256 ;
  file labels;
  set names end=eof;
  infile "/bdm/Data/all_studies_chkp_old.csv" dsd truncover lrecl=1000000 ;
  nliteral=nliteral(_name_);
  input label @ ;
  label = quote(trim(label),"'");
  if _n_=1 then put 'label';
  if label ne _name_ then put nliteral '=' label;
  if eof then put ';' ;
run;
proc datasets nolist lib=work;
  modify check;
%include labels / source2;
  run;
quit;

And if you want a tool to help you GUESS how to read a CSV file that will attach the labels automatically then use this macro instead of PROC IMPORT. 

https://github.com/sasutils/macros/blob/master/csv2ds.sas

 

 

 

chinna0369
Pyrite | Level 9

Sorry for the confusion I have column names length which has more than 32 characters in cvs file "checkpoint1_Startup_In_House_1_Yes_Reason" I am importing that file into sas but after importing to sas all those columns headers are converted into variables but all them are truncated. Can we get full column names into sas as a variable name? 

Tom
Super User Tom
Super User

@chinna0369 wrote:

Sorry for the confusion I have column names length which has more than 32 characters in cvs file "checkpoint1_Startup_In_House_1_Yes_Reason" I am importing that file into sas but after importing to sas all those columns headers are converted into variables but all them are truncated. Can we get full column names into sas as a variable name? 


Names in SAS can only use 32 bytes.  Use a different NAME for the variable than the column header in your CSV file.  Not only will it allow you to work with the data in SAS it will also make it much easier to work with the data since the names will not be too long to type or read or even display on page.

 

So for that column you might read it into a variable named REASON with a label attached to it with something like "Reason for Yes on Startup In House question at checkpoint number 1".

 

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