I want to format the variable plan. Right now it's $24 CHAR but the table it joins to later after this step has plan as $15. CHAR:
data table2 (keep=state plan);
rename state_r = state ptypcd=plan;
set table1;
run;
Have you checked to see if there is any value past the 15th character?
If so, you may need to make some decisions about what text value to keep.
The technique is simple: add a length statement to that data step before the Set statement:
data table2 (keep=state plan); rename state_r = state ptypcd=plan; length <variable> <new length i.e. $ 15>; set table1; run;
However your rename means that the variable name would be the OLD one so it modifies the existing variable what the values are brought in.
You are using the verb "format" ambiguously. In SAS a format is something that determines how to display a value as text. You can attach different formats to a variable and have the values display differently.
I suspect you want to change the LENGTH of a character variable. In that case you should also take care that the variable does not have a format attached to it that will impact how it is displayed.
If you want to change it to be length 15 from length 24 then you need to worry about lose of data. It might be safest to make a new variable and also check the current values before copying them to the new variable to make sure they will fit.
data table2 ;
set table1;
length plan $15 ;
state=state_r ;
plan=ptypcd ;
if length(ptypcd) > 15 then put 'NOTE: Data will be truncated. ' _n_= ptypcd= plan=;
keep state plan;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: