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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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

3 REPLIES 3
Linlin
Lapis Lazuli | Level 10

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

imanojkumar1
Quartz | Level 8

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?

marcomonti
Calcite | Level 5
Try with double dataset in set statement:
data want;
set have1
have2;
run;

note:have1 and have2 should have same PDV.

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 143966 views
  • 8 likes
  • 4 in conversation