BookmarkSubscribeRSS Feed
Balaji_7992
Calcite | Level 5

Kindly help me with the logic for this one

 

I am having a data set having 10 observations

like 

1

2

3

4

5

6

7

8

9

10

 

 

Need Output like

 

1

2

2

3

3

3

4

4

4

4

 

 

 
 

 

4 REPLIES 4
ed_sas_member
Meteorite | Level 14

Hi @Balaji_7992 

 

Here is a way to achieve this, using do loops:

data have;
	do i=1 to 10;
		output;
	end;
run;

data want;
	set have;
	do j=1 to i;
		k=i;
		output;
	end;
	drop j i;
run;

Best,

r_behata
Barite | Level 11
data have;
do i=1 to 10;
output;
end;
run;

data want;
	set have ;

	do _n_=1 to i;
		output;
	end;
run;
Shmuel
Garnet | Level 18

Suppose the values you have are not 1 to 10  but

2 4 6 8 ...

would you like to duplicate output according to the value or according to

its sequence?

should it be:

 2 2 4 4 4 4 6 6 6 6 6 6 ...

or

2 4 4 6 6 6 ...

 

mkeintz
PROC Star

Question:  why do you need to reproduce each record exactly X times, where X is an integer value (or rounded down to an integer) in your data set?   If it mearely is to facilitate analysis procedures, like proc freq, proc reg, etc., so that you are treating each row with the frequency of observations that X represents, you don't need to create the dataset you appear to want.

 

Instead, you can use the

   FREQ X;

statement in most analysis procedures, which will then treat each observation as if it appeared X times (or floor(X) times to be specific).

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 739 views
  • 0 likes
  • 5 in conversation