Hi All,
I have a below piece of code, where it creates a 3 output per iteration and between the iteration 1 minutes sleep. But now I want For each iteration separate log needs to be created in some location. I tried doing that. But for 1st iteration from 1 to 3 log is not creating. from 4 to 10 is creating. Please help me
%macro caller();
%do j=1 %to &npts;
%looper(subject=&&pt&j.);
%if %sysfunc(mod(&j,3))=0 %then
%do;
proc printto new log ='"/ctshared/cdr/dev/RAMYA/archive/logfile_&j..log";
run;
%let rc=%sysfunc(sleep(60,1));
%end;
%end;
%mend caller();
%caller();
With all suggested changes:
%macro caller();
%do j=1 %to &npts;
%if %sysfunc(mod(&j,3))=1 %then
%do;
proc printto new log ='"/ctshared/cdr/dev/RAMYA/archive/logfile_&j..log";
run;
%let rc=%sysfunc(sleep(60,1));
%end;
%looper(subject=&&pt&j.);
%end;
%mend caller();
Should be OK. Try it and see. Careful programming might eliminate an unnecessary SLEEP.
Please run this program again, with the following line as the first line of code to execute
options mprint mlogic symbolgen;
Are there errors in the SAS log file?
Please click on the {i} icon and paste the Log into the window that opens.
To tell you the truth, I would be surprised you get any logs at all because you have an error in this statement:
proc printto new log ='"/ctshared/cdr/dev/RAMYA/archive/logfile_&j..log";
You have a single quote followed by a double quote, the single quote doesn't belong there.
Also, wouldn't you want the corrected PROC PRINTTO higher in the code instead of where it is, such as:
%macro caller();
%do j=1 %to &npts;
proc printto new log ="/ctshared/cdr/dev/RAMYA/archive/logfile_&j..log";
run;
%looper(subject=&&pt&j.);
proc printto;
run;
%let rc=%sysfunc(sleep(60,1));
%end;
%mend caller();
%caller();
And lastly, why do you need to test if MOD(3,&j)=0? That doesn't seem to be doing anything useful to me.
I still need to see the SAS log, with the command options mprint mlogic symbolgen;
executed at the start of the program, and pasted into the {i} window (DO NOT SKIP THIS STEP)
@Ramya2 wrote:
@PaigeMiller
I need to use MOD(3,&j)=0 because, I need to execute 3 outputs at a time. the above will create 1 output each with a execution break of 1 minutes. But need 3 outputs together needs to be creted with the execution break of 1 minutes. Suppose if I have 10 subjects. 3 should execute and sleep for 1 minutes. Next 4 to 6 should execute and sleep for 1 minutes. And so on.
This was not explained previously. Now your MOD(3,&j) makes sense.
click on the {i} icon
I think that you may want
%if %sysfunc(mod(&j,3))=0 or &j=1 %then
mod (1,3) = 1
mod (2,3) = 2
so the mod function would prevent the printto code from running.
I don't know what your "looper" macro does but perhaps you want it run AFTER the proc printo if you want log results from looper to go to the printto file.
I think @Astounding has solved the problem, provided the code involving mod(&j,3)=1 is moved to above the %looper macro call.
Your PROC PRINTTO needs to be before %looper, not after.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.