DonnieCrump
DonnieCrump

Reputation: 169

Change variable length in SAS dataset

I need to change the variable length in a existing dataset. I can change the format and informat but not the length. I get an error. The documentation says this is possible but there are no examples.

Here is my issue. My data source could change so I don't want to pre define columns on import. I want to do a generic import and then look for certain columns and adjust the length.

I have tried PROC SQL and DATA steps. It looks like the only way to do this is to recreate the dataset or the column. Which I don't want to do.

Thanks, Donnie

Upvotes: 2

Views: 24277

Answers (3)

Puneet Tripathi
Puneet Tripathi

Reputation: 422

Length of a variable remains same once you set the dataset. Add length statements before you set the dataset if you need to change length of a columns

data a;
  length a, b, c $200 ;
  set b ;
run ;

Upvotes: 1

AFHood
AFHood

Reputation: 1040

The only way to change the length of a variable in a datastep is to define it before a source (SET) dataset is read in.

Conversely you can use an alter statement in a proc sql. SAS support alter statement

Upvotes: 1

Jay Corbett
Jay Corbett

Reputation: 28391

If you put your LENGTH statement before the SET statement, in a Data step, you can change the length of a variable. Obviously, you will get truncation if you have data longer than your new length.

However, using a DATA step to change the length is also re-creating the data set, so I'm confused by that part of your question.

Upvotes: 6

Related Questions