BookmarkSubscribeRSS Feed
DeJanae07
Calcite | Level 5

Changing the length of a Character Variable 

***************************************************************************************

Hello SAS Communities, 

 

I recently used proc import to import data from a .xls file. One of the variables within the data set is a character variable and the desired length is 11 variables long, however, after importing the data into my program the length of this variable is now 12. 

 

Here are the SAS Table Properties that show the variable length for the variable SSN and the proc import statement that I used: 

 

PROC IMPORT
            DATAFILE = "&CourseRoot/Study/Data/Source/DATA.xls"
            OUT = WORK.DATA
            DBMS = XLS
            REPLACE ;
    SHEET = "Sheet1";
    RUN;

 

Is there any way to change the variable length for SSN from 12 to 11?

 

Thank you,

De'Janae' Guillory-Williams 

3 REPLIES 3
Shmuel
Garnet | Level 18

You can change length of a variable, but you take a risk of assigning a too short and value might be truncated. The code is:

data want;  
     length SSN <new length>;
 set have;
run;
pink_poodle
Barite | Level 11
Longer is better than shorter, you can just re-set it with a length statement. Make sure that it follows right after the data statement.
Ksharp
Super User
data have;
set sashelp.class;
run;

proc sql;
alter table have
modify name char(20);
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 523 views
  • 1 like
  • 4 in conversation