- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I try to compute the nearest distance between the trees of a forest for a set of forests, each forest identified by a number. The input data look like this, where x and y are the coordinates of a tree:
`x y forest
1 3 1
2 3 1
.....
5 6 2
.....`
I would like to have the results saved in one file, also identifying the forest, something like that (other variable can appear too):
`tree1 tree2 distance forest
1 4 24 1
1 15 26 1
.....
1 16 3 2
.......`
I am using the proc variogram and the objective is the output file that computes the pair distances. I have the code working for one forest but I have 600 forests and I would like to automatize the process. I thought that a macro could help. This is what I have so far, but it give me errors as I have identify the forest for which the distances are computed:
%macro repeat;
%do forest= 1 %to 600;
Proc variogram data=data outpair=nndata;
compute outpdistance=15 novar;
coordinates xcoord=x ycoord=y;
run;quit;
%end;
%mend repeat;
%repeat;
Any suggestion on how to create the outpair data set is greatly appreciated.
Best wishes,
Nat
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Rather than writing a macro loop, why not use BY group processing:
Proc variogram data=data outpair=nndata;
by forest;
compute outpdistance=15 novar;
coordinates xcoord=x ycoord=y;
run;
Steve Denham
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Add a where clause?
%macro repeat;
%do forest= 1 %to 600;
Proc variogram data=data outpair=nndata;
compute outpdistance=15 novar;
coordinates xcoord=x ycoord=y;
WHERE FOREST = &FOREST ;
run;quit;
%end;
%mend repeat;
%repeat;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Rather than writing a macro loop, why not use BY group processing:
Proc variogram data=data outpair=nndata;
by forest;
compute outpdistance=15 novar;
coordinates xcoord=x ycoord=y;
run;
Steve Denham
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear Steve,
Thank you very much for your replay. I did not know that by statement can be sued inside variogram procedure. This solved all the problem.
Best wishes,
Nat
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I thought about the BY statement option but assumed there was some reason why you needed separate outputs for each forest code. The BY statement makes far better sense if you don't need separate output tables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear Fugue,
Thank you very much for your replay. It worked great, but it saved only the last dataset, as the rests were overwritten by the latest dataset created. A fast and easy solution was proposed by another user who said to use the by statement, which I did not know that can be used inside variogram procedure.
Best wishes,
Nat
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Sorry Nat, it was late and I was at home . . . I should have used a double ampersand . . . also, the output statement needed to be modified with a counter (&&forest), otherwise every iteration would overwrite the same dataset.
%macro repeat;
%do forest= 1 %to 600;
Proc variogram data=data outpair=nndata&&forest ;
compute outpdistance=15 novar;
coordinates xcoord=x ycoord=y;
WHERE FOREST = &&FOREST ;
run;quit;
%end;
%mend repeat;
%repeat;