BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ramya2
Calcite | Level 5

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();

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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.

View solution in original post

19 REPLIES 19
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Ramya2
Calcite | Level 5
@PaigeMiller

Apologies, Posted the code with typo error. In Program I have used proper quotes.
PaigeMiller
Diamond | Level 26

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. 

--
Paige Miller
Ramya2
Calcite | Level 5
@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.
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Ramya2
Calcite | Level 5
what is this i window?
PaigeMiller
Diamond | Level 26

click on the {i} icon

--
Paige Miller
Ramya2
Calcite | Level 5
Sorry, I am unable to find that icon.
ballardw
Super User

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.

Ramya2
Calcite | Level 5
@ballordw,

Here is my Looper macro, just before caller..


***checking whether any new entry for the onsetdt rslt endptid****;

/*data final_1;
merge final (in=a) test.History (in=b);
by _all_;
if a and not b;
run;*/

******relpacing the history file with current one****;

data test.history;
set final;
run;

******creating macro variable for site and subject to creat the output for each subject;

data _NULL_;
set final_1 end=eof;
call symput('pt'||compress(put(_n_,best.)),trim(left(upcase(subject))));

if eof then call symput('npts',compress(put(_n_,best.)));
run;

****creating macro variable to create or run the report conditionally******;

%let count=0;

data _null_ ;
set final_1 end=eof NOBS=COUNT;;
countc = put(count,best.);
if _n_ = 1 then call symput('count',countc);
run;
%put &count;


%macro new_entry;

%if &count ne 0 %then %do;

*****genrating the report and sent patient profile in attached the mail if new entry****;
*****selecting the subject only who have value for the endptid,event and onsetdt*****;

proc sql;
create table demo as
select *
from demog_1_
where subject in (select subject from final_1)
order by subject,site;
quit;

********************** Create profile for each patient*******************;

%macro looper(subject=,);

options papersize = A4 orientation = landscape nodate center nonumber bottommargin = 0.25in
topmargin = 0.25in leftmargin = 0.25in rightmargin = 0.25in ;
ods listing close;
/*ods pdf body = "/ctshared/cdr/prod/a423_20110203/AMG423_20110203_Patient_Profile/rms32763/AMG423_20110203_&subject._Patient Profile.pdf";*/
ods pdf body = "/ctshared/cdr/dev/RAMYA/AMG423_20110203_&subject._Patient Profile.pdf";
ods noresults;

footnote2 justify=left height=0.5 "Report Creation Date/Time: &sysdate. &systime. AM PDT" ;
footnote3 justify=left height=0.5 "For Internal Use Only. Amgen Confidential.";

Title1 Bold "AMG423_20110203_&subject._Patient Profile";
Title4 italic justify=left "Demographics";

PROC REPORT DATA=demo NOWD split='*' ;
where subject in ("&subject" "Subject");
column ("Demographics" site subject age_y_c sex svstdt_raw);

define site / Center Display "Site" style=[cellwidth=15mm];
define subject / Center Display "Subject" style=[cellwidth=22mm];
define age_y_c / Center Display "Age" style=[cellwidth=20mm];
define sex / Center Display "Sex" style=[cellwidth=20mm];
define svstdt_raw / Center Display "Screening Date" style=[cellwidth=20mm];

run;

ods PDF close; /* must close tagsets.ExcelXP here*/
ods listing;
ods results;

ods listing;

%mend looper ;

Astounding
PROC Star
You are looking for mod(&j,3)=0 but that is the wrong logic. It means there are no proc printtos until &j=3. Try switching to mod(&j,3)=1 instead.
PaigeMiller
Diamond | Level 26

I think @Astounding has solved the problem, provided the code involving mod(&j,3)=1 is moved to above the %looper macro call.

--
Paige Miller
Ramya2
Calcite | Level 5
@Astounding,

I have tried giving mod(&j,3)=1, But it is not coming as expected. Kindly find the details below.

My total number of subjects:10
20314001003
20314001004
20314001005
20314001006
20314001007
20314001008
20314001011
20314001013
20314001014
20314001015

My caller macro;
%macro caller();
%do j=1 %to &npts;

%looper(subject=&&pt&j.);
%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;
%end;
%mend caller();

%caller();

Log file details.
Logfile_1.log - 2nd subject to 4th subject
Logfile_4.log - 5th subject to 8th subject
Logfile_7.log - 9th subject to 10th subject
Logfile_10.log - no entry

But, I want 1st to 3rd , 4th to 6th ,7th to 9th and 10th
PaigeMiller
Diamond | Level 26

Your PROC PRINTTO needs to be before %looper, not after.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 19 replies
  • 1924 views
  • 0 likes
  • 4 in conversation