Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replicating or copying cases

2,034 views
Skip to first unread message

Chris

unread,
Jan 6, 2012, 4:01:14 PM1/6/12
to
Hi all!

By using syntax, which is the best way to make copy of case line ?

For exemple, let say I have a dataset which contains data for 17
regions. Each region has information on several variables. I want to
copy region1 and make 30 identical lines. Region2 could be duplicate
18 times, and so on. I don't want to make it manually with simple copy/
paste.

Other exemple:

Before:
region v1 v2 v3 v4
1 2 6 7 9
2 6 8 9 2
3 5 7 4 2

After:
region v1 v2 v3 v4
1 2 6 7 9
1 2 6 7 9
1 2 6 7 9
2 6 8 9 2
2 6 8 9 2
2 6 8 9 2
2 6 8 9 2
3 5 7 4 2
3 5 7 4 2

Is that clear enough?

Thank you for your concern.

Christian

Bruce Weaver

unread,
Jan 6, 2012, 5:55:39 PM1/6/12
to
On 06/01/2012 4:01 PM, Chris wrote:
> Each region has information on several variables. I want to
> copy region1 and make 30 identical lines. Region2 could be duplicate
> 18 times, and so on.

LOOP and XSAVE should do the trick. Something like this:

* Read in sample data.
data list list / region v1 v2 v3 v4 (5f2.0).
begin data
1 2 6 7 9
2 6 8 9 2
3 5 7 4 2
end data.

* Compute a scratch variable holding the desired
* number of rows for each region .
* This example shows how to do it for 3 regions;
* the OP will need to add more recodes for regions
* 4 to 17.

recode region
(1 = 30)
(2 = 18)
(3 = 5)
into #NumRows
.

* Use LOOP and XSAVE to write a file with the desired number
* of rows for each region.

loop copy = 1 to #NumRows.
xsave outfile = "C:\temp\expanded file.sav" / keep = copy all .
end loop.
execute.

get file = "C:\temp\expanded file.sav" .
formats copy (f5.0).
list.


--
Bruce Weaver
bwe...@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."

Chris

unread,
Jan 9, 2012, 10:09:44 AM1/9/12
to
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home
> "When all else fails, RTFM."


Thank you M. Weaver. It works perfectly.

Chris
0 new messages