PRINT DUPLICATES OF EACH RECORD BASED ON _N_ TIMES
eg: sno age sex
1 23 M
2 45 F
2 45 F
3 25 M
3 25 M
3 25 M
Nothing could be easier, surely:
data have;
infile cards dsd dlm=',' firstobs=2;
attrib sno age length=4;
attrib sex length=$ 1;
input sno
age
sex;
cards;
sno age sex
1,23,M
2,45,F
3,25,M
;
run;
data _null_;
set have;
do i = 1 to _n_;
put sno
age
sex;
end;
run;
Nothing could be easier, surely:
data have;
infile cards dsd dlm=',' firstobs=2;
attrib sno age length=4;
attrib sex length=$ 1;
input sno
age
sex;
cards;
sno age sex
1,23,M
2,45,F
3,25,M
;
run;
data _null_;
set have;
do i = 1 to _n_;
put sno
age
sex;
end;
run;
@LaurieFThank you...
Hello,
data have;
input sno age sex$;
datalines;
1 23 M
2 45 F
3 25 M
5 25 F
4 24 M
;
run;
proc print data=have;
Title " Input data set values";
run;
data want(drop=i j);
do i=1 to tot;
set have nobs=tot;
do j=1 to i;
output;
end;
end;
run;
proc print data=want;
Title "Required Dataset";
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.