diff --git a/PermutationOf.sas b/PermutationOf.sas new file mode 100644 index 0000000..cc0ac37 --- /dev/null +++ b/PermutationOf.sas @@ -0,0 +1,66 @@ +/* +by Jian Dai +https://www.clinovo.com/userfiles/PharmaSug-SAS-Macros-for-List-Permutations.pdf + +*/ + +%macro TheFirstWordOf(List=); + %scan(&List,1) +%mend; + +%macro ExceptTheFirstWord_SubListOf(List=); + %local L; %let L=%length(%TheFirstWordOf(List=&List)); + %if &L<%length(&List) %then %left(%substr(&List,%eval(1+&L))); +%mend; + +%macro ForEach(ItemRef,In=,Do=%nrstr(/* Nothing */)); + %if %left(%trim(&In))^= %then %do; + %let &ItemRef=%TheFirstWordOf(List=&In); + %unquote(&Do); + %ForEach(&ItemRef,In=%ExceptTheFirstWord_SubListOf(List=&In),Do=&Do) + %end; +%mend; + +%macro ComplementOfWord(w,In=); + %local _1stWord; + %if &In^= %then %do; + %let _1stWord=%TheFirstWordOf(List=&In); + %if &_1stWord=&w %then + %ComplementOfWord(&w, + In=%ExceptTheFirstWord_SubListOf(List=&In)); + %else &_1stWord %ComplementOfWord(&w, + In=%ExceptTheFirstWord_SubListOf(List=&In)); + %end; +%mend; + +%macro PermutationOf( +List, +SelectedPath=, +Execute=%nrstr(%put &SelectedPath;) +); + %If &List= %Then + %unquote(&Execute) ; + %Else %do; + %ForEach(word, In=&List, + Do=%nrstr( + %PermutationOf( + %ComplementOfWord(&word,In=&List), + SelectedPath=&SelectedPath &word, + Execute=&Execute + ) + ) + ) + %end; +%mend; +%PermutationOf(1 2 3 ) + + + +%let c=0; +%PermutationOf(1 2 3 4,Execute=%nrstr(%let c=%eval(&c+1);%put &c: &SelectedPath;)) + + +data Perm5; + %PermutationOf(1 2 3 ,Execute=%nrstr( + perm="&SelectedPath &word";output;)) +run; diff --git a/get_label.sas b/get_label.sas index 48db9a5..c9fcd21 100644 --- a/get_label.sas +++ b/get_label.sas @@ -1,4 +1,3 @@ - /* %put %get_label(sashelp.iris,SepalLength); */ @@ -6,11 +5,11 @@ %macro get_label(data,variable); %local label; %let dsid = %sysfunc(open(&data)); + %let dnum=%sysfunc(varnum(&dsid,&variable)); + %if &dsid %then %do; - %let label=%sysfunc(varlabel(&dsid,%sysfunc(varnum(&dsid,&variable)))); + %let label=%sysfunc(varlabel(&dsid,&dnum)); %let rc = %sysfunc(close(&dsid)); %end; &label; -%mend; - - +%mend; \ No newline at end of file diff --git a/toDoc/isblank.sas b/toDoc/isblank.sas new file mode 100644 index 0000000..2d0fc14 --- /dev/null +++ b/toDoc/isblank.sas @@ -0,0 +1,10 @@ +/* +https://www.marc.info/?l=sas-l&m=142177161422037&w=2 + +http://support.sas.com/resources/papers/proceedings09/022-2009.pdf +by Chang Y. Chung, John King +*/ + +%macro isblank(param); + %sysevalf(%superq(param)=,boolean) +%mend isblank; \ No newline at end of file