Created
May 25, 2021 06:53
-
-
Save rudvfaden/9855e4be67a5e7c0f78a11ee56c470b1 to your computer and use it in GitHub Desktop.
Finds all child-Parent relations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro pathtoroot(data=,Childid=,Parentid=); | |
data pathToRoot; | |
attrib pathToRoot length=$350; | |
attrib uuid length=$36; | |
run; | |
*Finder antal rækker i alt; | |
data _null_; | |
call symputx( "tot" ,tot); | |
stop; | |
set &data. nobs=tot; | |
run; | |
* for child=i findes alle parents; | |
option nonotes; | |
%do i= 1 %to &tot.; | |
data _null_; | |
nrec= &i; | |
set &data. point=nrec; | |
call symputx('uuid',&childid.); | |
stop; | |
run; | |
*Nested macro. Kalder sig selv så længe der findes en parent til den vaglte child; | |
%let hirakistr=; | |
%macro findParent(id=); | |
%let mother=; | |
data _null_; | |
set &data.; | |
where &childid.="&id"; | |
call symputx('mother',&parentid.); | |
run; | |
%let hirakistr=&hirakistr/&id; | |
*Tjekker om der findes en mother. Hvis ikke afsluttes loppet; | |
%if %length(&mother)>0 %then %do; | |
%findParent(id=&mother); | |
%end; | |
%else %do; | |
%return; | |
%end; | |
%mend; | |
%findparent(id=&uuid.); | |
* Samler data; | |
data temp_hiraki; | |
attrib pathToRoot length=$350; | |
pathToRoot="&hirakistr"; | |
uuid="&uuid"; | |
run; | |
data pathToRoot; | |
set pathToRoot temp_hiraki; | |
run; | |
%end; | |
option notes; | |
%mend; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment