DATA Step, Macro, Functions and more

Print duplicates of each record

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Print duplicates of each record

[ Edited ]

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


Accepted Solutions
Solution
‎03-15-2017 03:19 AM
Super Contributor
Posts: 251

Re: Print duplicates of each record

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;

View solution in original post


All Replies
Solution
‎03-15-2017 03:19 AM
Super Contributor
Posts: 251

Re: Print duplicates of each record

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;
Occasional Contributor
Posts: 11

Re: Print duplicates of each record

Occasional Contributor
Posts: 6

Re: Print duplicates of each record

[ Edited ]

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;

 

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 177 views
  • 2 likes
  • 3 in conversation