Calcite | Level 5

## Logic needed

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
Meteorite | Level 14

## Re: Logic needed

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,

Barite | Level 11

## Re: Logic needed

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

data want;
set have ;

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

## Re: Logic needed

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 ...

PROC Star

## Re: Logic needed

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.

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

--------------------------
Discussion stats
• 4 replies
• 490 views
• 0 likes
• 5 in conversation