DATA Step, Macro, Functions and more

adding a row by using DATA step

Accepted Solution Solved
Reply
Super Contributor
Posts: 276
Accepted Solution

adding a row by using DATA step

Hi..

   IDNAMEMARKS
100SANJEEV23
101SRINATH25
102SRIHARI

28

i want to add another row to the above data by using data step ...

Thanks in Advance....

(DATA AFTER ADDING THE ROW)

ID
NAMEMARKS
100SANJEEV23
101 SRIHARI25
102SRINATH28
103SRIKANTH30

Accepted Solutions
Solution
‎01-25-2012 01:12 PM
Super Contributor
Posts: 1,636

Re: adding a row by using DATA step

How about:

data have;

input ID$ NAME $ MARKS ;

cards;

100 SANJEEV 23

101 SRINATH 25

102 SRIHARI 28

;

data want;

length name $ 8;

set have end=eof;

output;

if eof then do;

   id='103';

   name='SRIKANTH';

   marks=30;

   output;

  end;

run;

proc print;run;

                                Obs      name      ID     MARKS

                                  1     SANJEEV     100      23

                                  2     SRINATH     101      25

                                  3     SRIHARI     102      28

                                  4     SRIKANTH    103      30

Linlin

View solution in original post


All Replies
Solution
‎01-25-2012 01:12 PM
Super Contributor
Posts: 1,636

Re: adding a row by using DATA step

How about:

data have;

input ID$ NAME $ MARKS ;

cards;

100 SANJEEV 23

101 SRINATH 25

102 SRIHARI 28

;

data want;

length name $ 8;

set have end=eof;

output;

if eof then do;

   id='103';

   name='SRIKANTH';

   marks=30;

   output;

  end;

run;

proc print;run;

                                Obs      name      ID     MARKS

                                  1     SANJEEV     100      23

                                  2     SRINATH     101      25

                                  3     SRIHARI     102      28

                                  4     SRIKANTH    103      30

Linlin

Frequent Contributor
Posts: 87

Re: adding a row by using DATA step

What if I want to add a row before first row in the above sample data?

 

Also if I sort it by Names and then want to imput a row before first row, how can it be done?

☑ This topic is SOLVED.

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

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