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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.