BookmarkSubscribeRSS Feed
Neha0909
Calcite | Level 5

Hi all, 

 

I am trying to create a program to predict the future visit dates from the baseline visit dates. The information provided to me is something like attached in the file

 

now i want to create a program which calculates the predicted visit date and also gives me the actual visit date. so that i can actually check if visit was performed within the required period or was it out of the window period.

 

please suggest how can i do this.

 

i tried the following method by creating a macro but i am stuck on how to use this macro within my dataset.

 

%macro visitdate (vsvar=VS , stdyvar=,visvar=);
%if vsvar=”B %then %do;
If &stdyvar = 1 then &visvar = 1;
Else if 28 <= &stdyvar <= 32 then &visvar=2;
Else if 91 <= &stdyvar <= 98 then &visvar=3;
Else if 182 <= &stdyvar <= 189 then &visvar=4;
Else if 273 <= &stdyvar <= 280 then &visvar=5;
Else if 364 <= &stdvar <= 371 then &visvar=6;
Else if 455 <= &stdvar <= 462 then &visvar=7;
Else if 546 <=&stdvar <= 553 then &visvar=8;
Else if 574 <=&stdvar <= 581 then &visvar=9;
If &visvar = .
Then put “War” “ning: Visit window error”;
%end;
%mend visitdate;

 

 

please help how do i create a program for this.

 

kind regards

Neha

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Since we don't really know what you are trying to do, and can't see the larger program to understand the context, it is impossible to give specific advice. Can we see a larger portion of the code? Please click on the running man icon and paste the code into that box. 

--
Paige Miller
Neha0909
Calcite | Level 5
Proc sort data=dm.dsrand out= dsrand (keep=subjid siteid country visit  form DSDAT);
by subjid siteid country;
run;

proc sort data=dm.sv out=sv (keep=subjid  siteid country visit visitnum form SVSDAT);
by subjid visit;
run;

proc sort data=dm.dsic out= ic (keep= subjid siteid country visit visitnum form DSPROT);
by subjid visit;
run;

data VS;
    retain subjid siteid country visit visitnum form DSPROT DSDAT SVSDAT;
    merge dsrand ic sv;
	by subjid siteid country;
	run;

/* deriving visits based on visit windows*/

%macro visitdate (vsvar=VS , stdyvar=,visvar=);
 %if vsvar=”B %then %do;
 If &stdyvar = 1 then &visvar = 1;
 Else if 28 <= &stdyvar  <= 32 then  &visvar=2;
 Else if 91 <= &stdyvar  <= 98 then  &visvar=3;
 Else if 182 <= &stdyvar <= 189 then &visvar=4;
 Else if 273 <= &stdyvar <= 280 then &visvar=5;
 Else if 364 <= &stdvar  <= 371 then &visvar=6;
 Else if 455 <= &stdvar  <= 462 then &visvar=7;
 Else if 546 <=&stdvar   <= 553 then &visvar=8;
 Else if 574 <=&stdvar   <= 581 then &visvar=9;
 If &visvar = .
 Then put “War” “ning: Visit window error”;
 %end;
%mend visitdate; 


%Macro visitdate (stdyvar=,visvar=);
proc sort data=VS;
by &stdyvar &visvar;
proc print data= VS;
Var subjid siteid country visit visitnum form DSPROT DSDAT SVSDAT;
%Mend;

i created this code but doesn't seem to work. 

 

i want to predict when would be the next scheduled visit for the patient due with the protocol visit schedule.

 

kind regards

neha

ballardw
Super User

@Neha0909 wrote:
Proc sort data=dm.dsrand out= dsrand (keep=subjid siteid country visit  form DSDAT);
by subjid siteid country;
run;

proc sort data=dm.sv out=sv (keep=subjid  siteid country visit visitnum form SVSDAT);
by subjid visit;
run;

proc sort data=dm.dsic out= ic (keep= subjid siteid country visit visitnum form DSPROT);
by subjid visit;
run;

data VS;
    retain subjid siteid country visit visitnum form DSPROT DSDAT SVSDAT;
    merge dsrand ic sv;
	by subjid siteid country;
	run;

/* deriving visits based on visit windows*/

%macro visitdate (vsvar=VS , stdyvar=,visvar=);
 %if vsvar=”B %then %do;
 If &stdyvar = 1 then &visvar = 1;
 Else if 28 <= &stdyvar  <= 32 then  &visvar=2;
 Else if 91 <= &stdyvar  <= 98 then  &visvar=3;
 Else if 182 <= &stdyvar <= 189 then &visvar=4;
 Else if 273 <= &stdyvar <= 280 then &visvar=5;
 Else if 364 <= &stdvar  <= 371 then &visvar=6;
 Else if 455 <= &stdvar  <= 462 then &visvar=7;
 Else if 546 <=&stdvar   <= 553 then &visvar=8;
 Else if 574 <=&stdvar   <= 581 then &visvar=9;
 If &visvar = .
 Then put “War” “ning: Visit window error”;
 %end;
%mend visitdate; 


%Macro visitdate (stdyvar=,visvar=);
proc sort data=VS;
by &stdyvar &visvar;
proc print data= VS;
Var subjid siteid country visit visitnum form DSPROT DSDAT SVSDAT;
%Mend;

i created this code but doesn't seem to work. 

 

i want to predict when would be the next scheduled visit for the patient due with the protocol visit schedule.

 

kind regards

neha


You have two different definitions for the macro visitdate [the stuff between %macro and %mend]

And then you do not actually use either of them which would be a statement something like:

%visitdate (vsvar=VS , stdyvar=varx, visvar=vary); for the first definition. Note that that first version has a serious issue indicated below in red:

%macro visitdate (vsvar=VS , stdyvar=,visvar=);
 %if vsvar=B %then %do;
 If &stdyvar = 1 then &visvar = 1;
 Else if 28 <= &stdyvar  <= 32 then  &visvar=2;
 Else if 91 <= &stdyvar  <= 98 then  &visvar=3;
 Else if 182 <= &stdyvar <= 189 then &visvar=4;
 Else if 273 <= &stdyvar <= 280 then &visvar=5;
 Else if 364 <= &stdvar  <= 371 then &visvar=6;
 Else if 455 <= &stdvar  <= 462 then &visvar=7;
 Else if 546 <=&stdvar   <= 553 then &visvar=8;
 Else if 574 <=&stdvar   <= 581 then &visvar=9;
 If &visvar = .
 Then put War ning: Visit window error;
 %end;
%mend visitdate; 

Those are "smart quotes" and will not be treated the same as the programming " you get when typing in the editor. You likely copied some code from a word processing or other document that was trying to be helpful by inserting those quotes.. I am pretty sure that attempting to actually execute that macro, which pretty much would have to be part of a data step, will generate an interesting list of syntax errors.

So some hints: rename one of those visit date macros, replace the smart quotes, fix this

Then put "War" "ning: Visit window error"; to have only one set of open/close quotes

 

I am really not sure why you make the default value for &visvar to be VS and apparently don't do anything unless the parameter is B.

Then actually call the macros in a reasonable location in the process.

 

Before you attempted the "macro" did you have code that worked? If not, make sure that you can get code that works as macros will not fix error logic issues. Show us the code that worked and indicate which pieces you need to parameterize for repeat usage.

 

I am very suspicious of that block of If then else range of values that are compared with &stdyvar. Most of those show a range of 7 making one suspect this data may have something to do with weeks, but 2 of them don't. Also what happens if the value is 66? Or have you forced the suspect variables you want to reference as &stdyvar in that range.

Neha0909
Calcite | Level 5

Thank you for your reply. in the end i dropped the use of macro and used simple method by using intnx to calculate the dates. and it worked fine.

 

tanks again

Neha

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1807 views
  • 0 likes
  • 3 in conversation