BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ram999
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
LaurieF
Barite | Level 11

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

3 REPLIES 3
LaurieF
Barite | Level 11

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;
Ram999
Calcite | Level 5

GPNaveen
Fluorite | Level 6

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;

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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