A. Usage
- Extract sub-string from a string in Macro
B. Code
%let newvar = %substr(&var., 3, %length(&var.)-2); *Newvar is trimming the first 2 characters off the var;
A journey of a thousand miles begins with the first step.
A. Usage
B. Code
%let newvar = %substr(&var., 3, %length(&var.)-2); *Newvar is trimming the first 2 characters off the var;
Need to put Length statement before the Set statement to change the length of existing variable. Use the LENGTH statement as the very first statement in the DATA STEP to declare the length of variable in the Set dataset.
thekey and program variables in the mapping dataset are both $7 in length. The following data step change the length of these two variables to $10.
data mapping; length thekey $10 program $10; set mapping; run;