turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- insert the last observation for every two or three...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

09-29-2015 12:09 PM

Hi, i have a data set like this

data test;

input x$ a b c;

cards;

A 1 2 3

B 4 5 6

C 7 8 9

D 1 2 6

E 3 7 9

Total 10 20 30

;

run;

I would like to create a data set like below. Which means i want to repeat the last row of my data set with every 2 records of my existing data set. Please help?

A 1 2 3

B 4 5 6

Total 10 20 30

C 7 8 9

D 1 2 6

Total 10 20 30

E 3 7 9

Total 10 20 30

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sas715626

09-29-2015 12:36 PM

By just quick looking at your sample data, it makes little sense. Perhaps you could use more realistic names/values? And tell us why you wish to do this...

Data never sleeps

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to LinusH

09-29-2015 01:03 PM - edited 09-29-2015 01:24 PM

Thanks for your response.

I have a real time scenario where if there are 100 rows and there will be a final row which is the sum of 100 rows , so total there will be 101 rows. I have to print 10 rows for each page + the sum row.The 11 th row is the sum of all 100 rows and nothing to do with the 10 rows. So it will be like 11 rows for 10 pages. Hope it is clear. Please let em know if you need more information w.r.t this

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sas715626

09-30-2015 05:11 PM

This sounds more like something for Proc Report than a data set issue. Data sets do not have pages but proc report has tools to break printed output at changes is the value of a grouping variable, to the sums (and other statistics) with in the group and then provide an overal summary at the end.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to sas715626

09-29-2015 04:56 PM

This should do the trick for you:

**data** test;

input x$ a b c;

cards;

A 1 2 3

B 4 5 6

C 7 8 9

D 1 2 6

E 3 7 9

Total 10 20 30

;

**run**;

**data** last;

set test end=end;

if end then output;

**run**;

**data** final(drop=lastx lasta lastb lastc);

set test end=end;

if _n_=**1** then set last(rename=(x=lastx a=lasta b=lastb c=lastc));

if mod(_n_,**2**)=**0** then do;

output;

x=lastx;

a=lasta;

b=lastb;

c=lastc;

end;

if not end then output;

**run**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to michelle_delaurentis_sas_com

09-29-2015 06:21 PM

Or

```
data TEST;
input X $ A B C;
cards;
A 1 2 3
B 4 5 6
C 7 8 9
D 1 2 6
E 3 7 9
Total 10 20 30
run;
data FINAL;
set TEST nobs=NOBS ;
if _N_ ne NOBS then output;
if mod(_N_,2)=0 then do;
set TEST point=NOBS ;
output;
end;
run;
```