Hi Everyone,
I have a long text variable and I want to split this variables in multiple variables (v1 to Vn) with equal number of character in each variables. Of course, the last variable should has the left-over.
In the example below, can you please help me to create variables with (10 letter and space) in each?
Thank you so much,
HHCFX
data have;
infile datalines dlm="|";
length var $ 30000;
input var $;
datalines;
<"myword myword: []/'\":+!@#$%& -0*&^% myword><W15ySpnsrCW1sA5ZZ0</W1urvA5ySpnsrCW1sA5ZZD><W1:RA5prozzznmUnzzozMA5ozW1dW1ozW1><W1:MA5oZozA5m></W1:MA5ozW1DW1ozW1Mrup><W1:MA5ozW1DW1ozW1Mrup MA5ozW1DW1ozW1MrupNW1mA5="A5CW1SA5_CS_MW1"><W1W1ozW1ZZ A5lA5mA5nozNW1mA5="WRKLW1D_OZYPA5_CDA5">myword</W1W1ozW1ZZoA5m><W1W1ozW1ZZozA5m A5lA5mA5nozNW1mA5="WRKLW1D_P_OZYPA5_CDA5"></1W1ozW1ZZozA5m></W1:MA5ozW1DW1ozW1Mrup></W1:RA5prozzznmUnzzozMA5ozW1dW1ozW1><WMW1zzlzznmW1ddrAW1ddr1>20OZ 11W1</W1:W1ddr1><W1:W1ddr3>NW1RRW1MW1NSA5OZOZ, RZZ -</W1:W1ddr3>myword;
run;
data want;
set have;
length nvar1-nvar9 $10. nvar10 $100.;
array nvar[*] $ nvar1-nvar10;
j=1;
do i=1 to 9;
nvar[i]=cats(substrn(var,j,10),' ');
j+10;
end;
j+10;
nvar[i]=substrn(var,j);
run;
data temp;
set have;
n+1;
length temp $ 4;
do i=1 to length(var) by 4;
temp=substr(var,i);
output;
end;
run;
proc print;run;
solution included in original post.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.