Help using Base SAS procedures

insert data in speicfic observation

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

insert data in speicfic observation

How to insert  data in speicfic observation(nth observation) in a dataset.?


Accepted Solutions
Solution
‎11-08-2012 08:07 AM
Super Contributor
Posts: 276

Re: insert data in speicfic observation

Hi ...

Do you mean you  want to add a row to a dataset after a specific observation???

If yes...Here is the way..

data test;

input id name$;

cards;

100 aaa

101 bbb

103 ddd

;

run;

Now i want to add a row after 2nd observation.  

data test1;

set test;output;

if _n_=2 then do;

id=102;

name="ccc";

output;

end;

run;

proc print;

run;

Thanks&Regards..

Sanjeev.K

View solution in original post


All Replies
Solution
‎11-08-2012 08:07 AM
Super Contributor
Posts: 276

Re: insert data in speicfic observation

Hi ...

Do you mean you  want to add a row to a dataset after a specific observation???

If yes...Here is the way..

data test;

input id name$;

cards;

100 aaa

101 bbb

103 ddd

;

run;

Now i want to add a row after 2nd observation.  

data test1;

set test;output;

if _n_=2 then do;

id=102;

name="ccc";

output;

end;

run;

proc print;

run;

Thanks&Regards..

Sanjeev.K

New Contributor
Posts: 3

Re: insert  data in speicfic observation

Posted in reply to kuridisanjeev

Thanks a lot.I need that..

Super Contributor
Posts: 276

Re: insert  data in speicfic observation

Nope..

please mark my answer as a correct answer..

Thanks..

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 282 views
  • 1 like
  • 2 in conversation