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
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,
data have;
do i=1 to 10;
output;
end;
run;
data want;
set have ;
do _n_=1 to i;
output;
end;
run;
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 ...
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).
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: