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
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;
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.
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;
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..
proc surveyselect out=number3 reps=3 rate=1 noprint; run;
data number;
input number;
cards;
1
2
3
4
5
;
run;
data want;
set number number number;
run;
proc sql;
create table want as
select b.number
from number(where=(number<=3)) a, number b
order by a.number,b.number;
quit;
data want;
set number(where=(number<=3));
do _n_=1 to nobs;
set number nobs=nobs point=_n_;
output;
end;
run;
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.