Assuming you want to add this column to existing data:
data want;
set have;
id = ceil(_n_ / 5);
run;
Is this what you are after ?
data want;
do i=1 to 5;
num=input(compress(repeat(i,5)),8.);
putlog num=;
output;
end;
drop i;
run;
Log : num=111111 num=222222 num=333333 num=444444 num=555555
data want;
do i=1 to 5;
j=1;
do while(j < 6);
num=i;
output;
j+1;
end;
end;
drop i j;
run;
data want;
do number = 1 to 42;
do _N_ = 1 to 5;
output;
end;
end;
run;
Perhaps this is what you are looking for:
data want;
do num=1 to 5;
output; output; output; output; output;
end;
run;
Assuming you want to add this column to existing data:
data want;
set have;
id = ceil(_n_ / 5);
run;
data new;
set old;
string=repeat(strip(put(int(_n_/5) +1,$32.)),5);
if mod(_n_,5) ==0 then string=repeat(strip(put(int(_n_/5) ,$32.)),5);
run;
Is this what you want?
In pedantic mode I would say that you have conflicting requirements: "unique number" and "five times". Unique means one value.
And how many times is "so on"? How do we know when to quit? Are you attempting to add this value to an existing data set? Build a data set that only has this sequence?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.