BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasthebest
Calcite | Level 5

Is possible to change variable length without creating a new dataset using proc dataset or sql?

Example:

proc datasets library=work nolist;

modify datset

format variabe $5

length variable 10;

run;

Proc sql;

alter table dataset

modify variabe format = $5

modify length variable 10;

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Scott_Mitchell
Quartz | Level 8

Unfortunately there is no way to modify the length of a variable using the proc datasets modify function, however on the bright side you can use it to alter the format.

data have;

attrib var1 format = $15.;

var1 = '1234567890';

run;

proc contents data=have;

run;

proc datasets library=work nolist;

modify have;

format var1 $4.;

run;

proc contents data=have;

run;

View solution in original post

5 REPLIES 5
Scott_Mitchell
Quartz | Level 8

Unfortunately there is no way to modify the length of a variable using the proc datasets modify function, however on the bright side you can use it to alter the format.

data have;

attrib var1 format = $15.;

var1 = '1234567890';

run;

proc contents data=have;

run;

proc datasets library=work nolist;

modify have;

format var1 $4.;

run;

proc contents data=have;

run;

Patrick
Opal | Level 21

Changing variable attributes like format and informat needs only a change of the descriptor part of a data set. This can be done by either Proc Datasets or Proc SQL Alter table.

For  changing the variable length the data set needs to be re-written as this also changes how the data gets physically stored (more or less space required). This can not be done using Proc Datasets but it can be done using PROC SQL ALTER TABLE / MODIFY. Be aware that if you change the length the full data set gets re-written so this could take a bit of time for a big table.

Scott_Mitchell
Quartz | Level 8

Hi Patrick,

How does the SQL method compare efficiency wise to using a Datastep?

Regards,

Scott

Patrick
Opal | Level 21

The SQL approach will maintain all table attributes like indexes so it's imho the cleanest way of coding a change of variable lengths.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 5 replies
  • 6119 views
  • 4 likes
  • 4 in conversation