- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data have;
do i=1 to 10;
output;
end;
run;
data want;
set have ;
do _n_=1 to i;
output;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------