Something like:
data have; id=1; number="65747 736356 837364 837336"; output; id=2; number="556773 6738373 8373839 677838"; output; run; data want (drop=i number); set have; number=compress(number); length want $4.; do i=1 to lengthn(number); want=cats(want,char(number,i)); if mod(i,4)=0 then do; output; want=""; end; end; run;
something like this.
data have;
input Name$1-3 number$5-50;
datalines;
id1 65747 736356 837364 837336
id2 556773 6738373 8373839 677838
;
data want(keep=name num);
set have;
comp_number=compress(number);
nchar=length(comp_number);
do i=1 to nchar by 4;
num=substr(comp_number, i, 4);
output;
end;
run;
This is different to what you asked for in the first post. Also, you should really show this as wanted output, i.e. what spaces are to be used. As such you maybe able to modify @PeterClemmensen's code slightly to:
data have;
id=1; number="65747 736356 837364 837336"; output;
id=2; number="556773 6738373 8373839 677838"; output;
run;
data want (drop=i number);
set have;
length want $4.;
do i=1 to length(number) by 4;
want=substr(number,i,4);
output;
end;
run;
@JT99, there doesn't seem to bee spaces in the desired output data you post? Always a good idea to be clear about what your desired data looks like.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.