BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Saba1
Quartz | Level 8
Hi
I want to create a sequence of unique numbers in a column, but each number must repeat 5 times (i.e. same number in 5 rows). For example number 1 in first five rows, then number 2 must again repeat five times and so on.
Please help. Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Assuming you want to add this column to existing data:

 

data want;
set have;
id  = ceil(_n_ / 5);
run;
PG

View solution in original post

8 REPLIES 8
r_behata
Barite | Level 11

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
Saba1
Quartz | Level 8
@r_behata: thanks. No, i want "1" to be in first five rows, then "2" in next 5 rows, and so on.
r_behata
Barite | Level 11
data want;
	do i=1 to 5;
		j=1;
		do while(j < 6);
			num=i;
			output;
			j+1;
		end;
	end;

	drop i j;
run;
yabwon
Onyx | Level 15
data want;
  do number = 1 to 42;
    do _N_ = 1 to 5;
      output;
    end;
  end;
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Astounding
PROC Star

Perhaps this is what you are looking for:

 

data want;
do num=1 to 5;
   output; output; output; output; output;
end;
run;
PGStats
Opal | Level 21

Assuming you want to add this column to existing data:

 

data want;
set have;
id  = ceil(_n_ / 5);
run;
PG
smantha
Lapis Lazuli | Level 10
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?

ballardw
Super User

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?

SAS Innovate 2025: Register Now

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!

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
  • 8 replies
  • 3762 views
  • 7 likes
  • 7 in conversation