Hi! I have the following syntax, but the PATAGE variable I created is just spitting out "." in all value slots. Can someone please tell me where my error is? Thanks!!
data want;
set have;
keep admdate admdx DX1-DX20 marital pasth bencatx patdob dds dispdate dmisbenf dmissex ethnic pasth patcat patname paygrade prvadm race patage recage;
format dispdate mmddyy10.;
format admdate mmddyy10.;
format birtdate mmddyy10.;
patdob =birtdate;
format patdob mmddyy10.;
patage= Int(yrdif(N_patdob,N_admdate,'actual'));
run;
Just one more piece of advice: It's always helpful for yourself and for people who read or work with your programs to keep the code consistent, even in cases where this consistency is not necessary for proper functioning.
For us to really know what's going on you need to provide sample data for "have".
What is the SAS log telling you? Any warnings or notes about unititialized variables or missing values?
Just by looking into your code:
- N_patdob and N_admdate are variables sourced from "have". What are their values? If any of the two is missing then the result will be missing.
- Instead of Int(yrdif(N_patdob,N_admdate,'actual')) use intck('year',N_patdob,N_admdate,'c')
Without seeing sample data it's hard to say exactly what's wrong. Try adding n_patdob , n_admdate to your keep statement to make sure they have values and are valid numerics (SAS dates presumably).
If you could post some sample of your data, masked if it's a matter of P.H.I or P.I.I. Your approach seems fine though syntactically as this works..
data _null_;
n_patdob='10APR1988'd;
n_admdate='20NOV2015'd;
int_age_act=int(yrdif(n_patdob, n_admdate, 'actual'));
put int_age_act= ;
run;
The third parameter of yrdif should be "age". If you don't get error messages it may be that that part of the code is never executed. All attempts I have made to generate missing values resulted in error messages. This is what I tried:
data _null_;
/* Proper dates */
patdobD = '15JAN2000'd;
patadmD = '15JAN2015'd;
/* Non integer dates */
patdobDF = '15JAN2000'd + 0.4;
patadmDF = '15JAN2015'd + 0.6;
/* Datetimes instead of dates */
patdobDT = '15JAN2000:00:00:00'dt;
patadmDT = '15JAN2015:00:00:00'dt;
format patdobD patadmD patdobDF patadmDF date9.
patdobDT patadmDT datetime.;
do type = "actual", "age";
/* Age calculation with proper dates */
ageD = yrdif(patdobD, patadmD, type);
/* Age calculation with fractional dates */
ageDF = yrdif(patdobDF, patadmDF, type);
/* Age calculation with datetimes */
ageDT = yrdif(patdobDT, patadmDT, type);
/* Age calculation with missing value */
ageMiss = yrdif(patdobD, ., type);
/* Age calculation with dates in reversed order*/
ageReverse = yrdif(patadmD, patdobD, type);
put (_all_) (=/) /;
end;
run;
Just one more piece of advice: It's always helpful for yourself and for people who read or work with your programs to keep the code consistent, even in cases where this consistency is not necessary for proper functioning.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: