DATA Step, Macro, Functions and more

do loop

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

do loop

i want to run the macro %anova_wocf_mi in several visits. But the program only execute one time (where avisitn=6). Is any issue with my program?

 

data avisit;
  length paramcd  chg $8;
  mi=1;
  paramcd = "NPS0203";
  do i =6, 7, 8, 9, 10; 
    avisitn = i;
	chg=compress(catx('','chg',i));
    output;
  end;
  paramcd = "LMS0108";
  do i =8, 10; 
    avisitn = i;
	chg=compress(catx('','chg',i));
    output;
  end;
  paramcd = "UPSIT101";
   do i =3, 6, 7, 8, 10; 
    avisitn = i;
	chg=compress(catx('','chg',i));
    output;
  end;
  paramcd = "FEV1";
   do i = 6, 7, 8, 10; 
    avisitn = i;
	chg=compress(catx('','chg',i));
    output;
  end;
run;

%let paramcd=NPS0203;

 proc sql noprint;
    select  avisitn into: vis separated by "-"
        from avisit
            where paramcd="&paramcd." 
    ;
quit;

%put &vis;

%include mac_a(anova_wocf_mi.sas);

%macro loop;
    %do i=1 %to %sysfunc(countw(&vis,%str(-)));
        %let ppp=%scan(&vis,&i, -);
        %put &ppp;
		%anova_wocf_mi(paramcd=NPS0203, avisitn=&ppp., censornum=2, popoth=);
		%end;
%mend loop;
%loop;

Accepted Solutions
Solution
‎12-19-2017 04:28 AM
New Contributor
Posts: 4

Re: do loop

Thanks a lot. this is because before the model, we have to impute the data by MI and WOCF which is different by different visits.

 

The issue has been fixed now. that's because there is another do loop which use i as index in %anova_wocf_mi macro. if i is replaced by jj, then the do loop will be fine.

 

%macro loop;
    %do jj=1 %to %sysfunc(countw(&vis,%str(-)));
        %let visn=%scan(&vis,&jj, -);
        %put &visn;
		%ancova_wocf_mi(paramcd=NPS0203, avisitn=&visn., censornum=2, popoth=);
		%end;
%mend loop;
%loop;

 

View solution in original post


All Replies
Super User
Super User
Posts: 9,465

Re: do loop

Why do it that way in the first place?  SAS i built on the concept of by group processing, which is simpler coding, more robust, and faster.

proc anova data=...;
  by avisitn;
  class ...;
  model Relief = .../...;
run;

That code can replace all of what you have from %let onward.

Solution
‎12-19-2017 04:28 AM
New Contributor
Posts: 4

Re: do loop

Thanks a lot. this is because before the model, we have to impute the data by MI and WOCF which is different by different visits.

 

The issue has been fixed now. that's because there is another do loop which use i as index in %anova_wocf_mi macro. if i is replaced by jj, then the do loop will be fine.

 

%macro loop;
    %do jj=1 %to %sysfunc(countw(&vis,%str(-)));
        %let visn=%scan(&vis,&jj, -);
        %put &visn;
		%ancova_wocf_mi(paramcd=NPS0203, avisitn=&visn., censornum=2, popoth=);
		%end;
%mend loop;
%loop;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 160 views
  • 0 likes
  • 2 in conversation