## Multiplying a dataset

Solved
Occasional Contributor
Posts: 5

# Multiplying a dataset

[ Edited ]
``````data number;
input number;
cards;
1
2
3
4
5
;
run;``````

i want output like this :

``````Number
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5``````

please suggest a way to do this

Accepted Solutions
Solution
Friday
PROC Star
Posts: 1,283

## Re: base sas

Why do you want to do this?

One way (among many).

``````data number;
input number;
cards;
1
2
3
4
5
;
run;

data want;
set number;
do i=1 to 3;
output;
end;
run;

proc sort data=want out=want(drop=i);
by i;
run;``````

All Replies
Super Contributor
Posts: 339

## Re: base sas

Hi,

As you just want a suggestion, see what the following does then try and change it to suit your needs. The input data set has 19 observations, but it is being read twice:

``````data want;
set sashelp.class
sashelp.class
;
run;``````

If you are new to SAS, they do have some basic free training and paid-for training options available:

http://support.sas.com/training/

If you are still stuck then show us what code you have tried and the log with any messages.

Regards,

Amir.

Solution
Friday
PROC Star
Posts: 1,283

## Re: base sas

Why do you want to do this?

One way (among many).

``````data number;
input number;
cards;
1
2
3
4
5
;
run;

data want;
set number;
do i=1 to 3;
output;
end;
run;

proc sort data=want out=want(drop=i);
by i;
run;``````
Super User
Posts: 10,217

## Re: Multiplying a dataset

[ Edited ]

Another idea, in one data step:

``````data want;
do i = 1 to 3;
do j = 1 to nobs;
set number nobs=nobs point=j;
output;
end;
end;
drop i j;
stop;
run;``````

PS and use more intelligent subjects in the future. "base sas" in the Base SAS Programming community is not meaningful AT ALL..

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Posts: 3,852

## Re: Multiplying a dataset

```proc surveyselect out=number3 reps=3 rate=1 noprint;
run;```
PROC Star
Posts: 1,784

## Re: Multiplying a dataset

``````data number;
input number;
cards;
1
2
3
4
5
;
run;

data want;
set number number number;
run;``````
PROC Star
Posts: 1,784

## Re: Multiplying a dataset

``````proc sql;
create table want as
select b.number
from number(where=(number<=3)) a, number b
order by a.number,b.number;
quit;``````
PROC Star
Posts: 1,784

## Re: Multiplying a dataset

``````data want;
set number(where=(number<=3));
do _n_=1 to nobs;
set number nobs=nobs point=_n_;
output;
end;
run;``````
PROC Star
Posts: 1,784

## Re: Multiplying a dataset

``````data want;
if _N_ = 1 then do;
if 0 then set number;
dcl hash h(dataset:"number", ordered: 'yes');
dcl hiter i('h');
h.defineKey('number');
h.defineData('number');
h.defineDone();
end;
set number (where=(number<=3));
do while (1);
if i.next() ne 0 then return;
output;
end;
run;``````
☑ This topic is solved.