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

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;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
1 REPLY 1
hhchenfx
Rhodochrosite | Level 12

solution included in original post.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 659 views
  • 0 likes
  • 1 in conversation