Trivial Date Tasks PROC FCMP Can Help Pharmasug

Trivial Date Tasks Proc Fcmp Can Help Pharmasug-PDF Download

  • Date:03 Mar 2020
  • Views:18
  • Downloads:0
  • Pages:10
  • Size:352.98 KB

Share Pdf : Trivial Date Tasks Proc Fcmp Can Help Pharmasug

Download and Preview : Trivial Date Tasks Proc Fcmp Can Help Pharmasug


Report CopyRight/DMCA Form For : Trivial Date Tasks Proc Fcmp Can Help Pharmasug


Transcription:

The purpose of code above is to create a function called NUMDATE and a CALL routine called NUMDT that convert the. below character date variable into numeric,dt 2014 10 15. Now let s look into the code,1 outlib sasuser test date. This statement creates a data set TEST under SAS library SASUSER with package named DATE. 2 function NumDate dt, function is the keyword to create functions dt is the argument to be used in this function means this. argument should be a string argument The value of this argument is copied and passed to the function and. therefore ensures the original value would not be altered. 3 return n, To return the value of this function use return statement followed by an enclosed parentheses If the value. to return is a string then another sign will need to be added outside of the parentheses in function. endsub statement ends the declaration of a function or a CALL routine. 5 subroutine NumDt dt num dt2, subrontine is the keyword to declare a CALL routine Similar to function statement string arguments.
should be specified with symbol,6 outargs num dt2, outargs statement specifies argument from the argument list that you want subroutine to update. return statement for subroutine is optional and does not come with enclosed parentheses. After examining the code let s test the function and CALL routine Numeric version of date 2014 10 15 in DATE9. format is expected,option cmplib sasuser test 8,retain num dt2. num dt1 NumDate dt,call NumDt dt num dt2,put num dt1. put num dt2,format num dt1 num dt2 date9,dt 2014 10 15. num dt1 15OCT2014,num dt2 15OCT2014, NOTE There w ere 1 observations read from the data set WORK DTS.
NOTE DATA statement used Total process time,real time 0 09 seconds. cpu time 0 09 seconds,8 option cmplib sasuser test. This statement specifies SAS data set TEST under libref SASUSER that contain compiler subroutines to. include during program compilation, As we can see the outcomes of function and CALL routine are matching with expectation. THREE DIMENSIONAL CONCOMITANT MEDICATION FLAG CLASSIFICATION. Yam 2004 proposed a thorough discussion of creating concomitant medication flag by three dimensional. classification,S 0 S 1 S 2 S 3,E 0 Prior Prior Concomitant Post. Concomitant Concomitant Post,E 1 Prior Prior Error Error.
E 2 Prior Prior Concomitant Error,Concomitant Concomitant. E 3 Prior Prior Concomitant Post,Concomitant Concomitant Post. S is the comparison outcome among non study drug onset date study drug start date and study drug end date. S 0 means non study drug onset date is missing, S 1 means non study drug onset date is prior to study drug start date. S 2 means non study drug onset date is no earlier than study drug start date and not later than study drug. S 3 means non study drug onset date is later than study drug end date. E is the comparison outcome among non study drug end date study drug start date and study drug end date Its. values of 0 1 2 3 have definitions in similar fashion with S. CREATING FUNCTION DateComp, First let s start with building function DateComp The purpose of this function is to compare dates including both. complete and partial dates Since we are only to demonstrate the method we assume that both study drug start date. and end date are non missing and complete with year month and day This could be a safe assumption since these. two dates are most likely to appear in numeric format in ADaM datasets It is not possible for them to be partial. Another assumption would be the format of incoming date is ISO8601 and no time part is existing This is also a. reasonable assumption as ISO8601 format is suggested by CDISC Study Data Tabulation Model SDTM. implementation guide,Use the code below to create a dummy data set.
length ymd ym y trtsdt trtedt 10,ymd 2014 10 15,ym 2014 09. trtsdt 2014 10 01,trtedt 2014 10 30, Now we need to define the comparison rule Comparison will be made up to the dates lowest level That is if day. part is missing then only year and month will be compared and if day and month parts are missing then only year will. be compared If any of the date is missing then the return of function will be 0 which means missing Given this rule. the expected outcomes of function DateComp implemented over variable YMD YM Y and miss should be 2 1 3 and. 0 respectively,options cmplib null,proc fcmp outlib sasuser funcs date. function DateComp dt sdt edt,length xxdt xxsdt xxedt 10 9. if lengthn dt 0 then n 0,if lengthn dt 10 then do,xxdt substrn dt 1 10.
xxsdt sdt 10,else if lengthn dt 7 then do,xxsdt substrn sdt 1 7 11. xxedt substrn edt 1 7,else if lengthn dt 4 then do. xxsdt substrn sdt 1 4,xxedt substrn edt 1 4,if xxdt xxsdt then n 1. else if xxsdt xxdt xxedt then n 2,else if xxdt xxedt then n 3. As we can see the program above is using DATA step syntax familiar to a SAS user One thing worth paying. attention is that as mentioned before function or subroutine will not make any modification to original value This. means the input variables are read only unless they have been listed in outargs statement within subroutine By. looking at arrow 9 10 and 11 above we will notice that new local variables have been created and values of input. variables have been passed over to them These values can be either changed or unchanged Now let s apply this. function to dummy data we just created,options cmplib sasuser funcs.
n1 DateComp ymd trtsdt trtedt,n2 DateComp ym trtsdt trtedt. n3 DateComp y trtsdt trtedt,n4 DateComp miss trtsdt trtedt. put ymd trtsdt trtedt n1,put ym trtsdt trtedt n2,put y trtsdt trtedt n3. put miss trtsdt trtedt n4, ymd 2014 10 15 trtsdt 2014 10 01 trtedt 2014 10 30 n1 2. ym 2014 09 trtsdt 2014 10 01 trtedt 2014 10 30 n2 1. y 2015 trtsdt 2014 10 01 trtedt 2014 10 30 n3 3,miss trtsdt 2014 10 01 trtedt 2014 10 30 n4 0.
NOTE There w ere 1 observations read from the data set WORK DTS. NOTE DATA statement used Total process time,real time 0 14 seconds. cpu time 0 10 seconds, As we can see the results of function DateComp over variables YMD YM Y and MISS are just exactly as what we. desired Creation of this function is done Now what if we want to impute the partial dates. CREATING FUNCTION DateImpute, Different with function DateComp the purpose of this function is to impute single partial date under pre defined. imputation rule In most clinical trials this rule should be well written in Statistical Analysis Plan SAP Now to. demonstrate this example let s use the easiest and most conservative rule That is. For drug start date, If day is missing and year and moth are present then impute this date as the first day of the month. If day and month are missing and year is present then impute the date as the first day of the year. If all day and month and year are missing then this date will not be imputed. For drug end date, If day is missing and year and moth are present then impute this date as the last day of the month.
If day and month are missing and year is present then impute the date as the last day of the year. If all day and month and year are missing then this date will not be imputed. As what we did previously a dummy data set will be created. length id 1 cmstdtc cmendtc 10,cmstdtc 2014 10 15,cmendtc 2014 11 15. cmstdtc 2014 09,cmendtc 2014 10,cmstdtc 2015,cmendtc 2014. Variable CMSTDTC is the concomitant medication onset date and variable CMENDTC is the concomitant medication. end date After the imputation below result is expected. For ID 1 CMSTDTC 2014 10 15 and CMENDTC 2014 11 15. For ID 2 CMSTDTC 2014 09 01 and CMENDTC 2014 10 31. For ID 3 CMSTDTC 2015 01 01 and CMENDTC 2014 12 31. Now let s see how the program is built,proc fcmp outlib sasuser funcs date. function dateImpute dt type 10 12,length mdt 10 xxy 4 xxm xxd 2. xxy substrn compress dt 1 4,xxm substrn compress dt 6 2.
xxd substrn compress dt 9 2,if type 1 then do, if cmiss xxy xxm xxd 3 or notdigit compress xxy 0 then n. if missing xxm or notdigit compress xxm 0 then do, else if missing xxd or notdigit compress xxd 0 then do. n mdy input xxm best input xxd best input xxy best. else if type 2 then do, if cmiss xxy xxm xxd 3 or notdigit compress xxy 0 then n. if missing xxm or notdigit compress xxm 0 then do, else if missing xxd or notdigit compress xxd 0 then do. xxd substrn strip put intnx 13,month input catx,compress dt 15 yymmdd10 0 e.
n mdy input xxm best input xxd best input xxy best. mdt if not missing n then strip put n yymmdd10 else 14. return mdt,There are several points to note, Arrow 12 as mentioned before by adding the sign outside of parentheses SAS will know that string value. will be returned at the end of this function In this case we want to directly return the imputed date in. ISO8601 format If numeric value is expected which could be even more likely as in most cases imputed. dates are saved as analysis date ASTDT just remove the sign and the trailing length Also you may have. noticed another argument TYPE has been added By using this argument we will be able to apply different. imputation algorithm to start date and end date, Arrow 13 a SAS default function INTNX is used here By using the modifier e the ending of this interval will. be returned Since a complete numeric date is expected as argument of function INTNX day 15 is added. temporarily to pad the partial date as XXXX XX 15, Arrow 14 IF expression is used here This type of expression is supported by PROC FCMP but not DATA. step It has the same function as traditional two pieces IF THEN statements but not as complex. Now let s test the function,options cmplib sasuser funcs. length m cmstdtc m cmendtc 10,m cmstdtc DateImpute cmstdtc 1.
m cmendtc DateImpute cmendtc 2,put id cmstdtc m cmstdtc cmendtc m cmendtc. id 1 cmstdtc 2014 10 15 m cmstdtc 2014 10 15 cmendtc 2014 11 15 m cmendtc 2014 11 15. id 2 cmstdtc 2014 09 m cmstdtc 2014 09 01 cmendtc 2014 10 m cmendtc 2014 10 31. id 3 cmstdtc 2015 m cmstdtc 2015 01 01 cmendtc 2014 m cmendtc 2014 12 31. NOTE There w ere 3 observations read from the data set WORK DTS. NOTE DATA statement used Total process time,real time 0 12 seconds. cpu time 0 10 seconds, Just as what we expected partial dates have been imputed in the way they should be and meanwhile complete dates. remain the same Building of function DateImpute is done Now we can move forward to the final step that is to. create a CALL routine for concomitant medication flags. CREATING CALL ROUTINE CMFlag, With the existing two functions DateComp and DateImpute the task of creating CALL routine CMFlag becomes. straightforward As usual let s first get the mock data. length id 1 cmstdtc cmendtc trtsdt trtedt 10,cmstdtc 2014 10 15.
cmendtc 2014 11 15,trtsdt 2014 10 01,trtedt 2014 10 30. cmstdtc 2014 09,cmendtc 2014 10,trtsdt 2014 10 15,trtedt 2014 11 30. cmstdtc 2015,cmendtc 2013,trtsdt 2014 08 01,trtedt 2014 09 15. What concomitant medication flags should we get By referring to the previous classification chart. For ID 1 S equals to 2 and E equals to 3 So concomitant and post concomitant flag should be marked. For ID 2 S equals to 1 and E equals to 2 So pre concomitant and concomitant flags should be marked. For ID 3 S equals to 3 and E equals to 1 So this is a data error and an error flag should be marked. Now let s look at the actual code,proc fcmp outlib sasuser funcs date. subroutine CMFlag cmsdt cmedt sdt edt prefl confl postfl. outargs prefl confl postfl errfl,length xxcmsdt xxcmedt 10.
xxcmsdt DateImpute cmsdt,xxcmedt DateImpute cmedt,S DateComp xxcmsdt sdt edt. E DateComp xxcmedt sdt edt,call missing prefl confl postfl errfl. if S E 0 then do,if S in 0 1 then prefl Y,if S 3 and E 1 then confl Y. if E not in 1 2 then postfl Y,if S 1 then prefl Y,if S in 1 2 and E in 2 3 then confl Y. if E 3 then postfl Y,if S E then errfl Y, As we can see with pre define function DateComp and DateImpute the subroutine has become relatively short With.
several lines of IF THEN logic the cooking is done Now let s test. options cmplib sasuser funcs,retain prefl confl postfl errfl. call CMFlag cmstdtc cmendtc trtsdt trtedt prefl confl postfl errfl. put id cmstdtc cmendtc trtsdt trtedt prefl confl postfl errfl. id 1 cmstdtc 2014 10 15 cmendtc 2014 11 15 trtsdt 2014 10 01 trtedt 2014 10 30 prefl confl Y. postfl Y errfl, id 2 cmstdtc 2014 09 cmendtc 2014 10 trtsdt 2014 10 15 trtedt 2014 11 30 prefl Y confl Y postfl. id 3 cmstdtc 2015 cmendtc 2013 trtsdt 2014 08 01 trtedt 2014 09 15 prefl confl postfl. NOTE There w ere 3 observations read from the data set WORK DTS. NOTE DATA statement used Total process time,real time 0 26 seconds. cpu time 0 21 seconds, From the SAS log we can see all the results are matching with what we expected above The declaration of CALL. routine CMFlag is completed, Debugging is always a topic for tool development As one of the most powerful weapons in debugging arsenal PUT.
statement plays an important role in debugging The good news is the PUT statement is supported by PROC FCMP. However PUT statement operates slightly different in PROC FCMP First PUT statement in PROC FCMP evaluates. expressions by enclosing the expression in parentheses For example X 100 will generate error in a DATA step. Trivial Date Tasks PROC FCMP Can Help at some basic syntax of PROC FCMP to build functions and CALL routines Then two else do if lengthn dt gt 10 then do

Related Books