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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

 

  • You bother to format variable BIRTDATE nicely, although this variable is not kept (hence dropped) anyway, so that the assigned format will never be effective.
  • It looks like variable PATDOB takes over from BIRTDATE. If it's just a change of names, you can use a RENAME statement (or RENAME= dataset option) to achieve this more easily.
  • It's a bit odd that neither the just created numeric date variable PATDOB (patient's date of birth, I guess) is used in the calculation of PATAGE (presumably patient's age), nor the numeric date variable ADMDATE. Instead, you use two seemingly similar variables N_PATDOB and N_ADMDATE. Does the "N_" prefix, by any chance, stand for "numeric", i.e. SAS date value as opposed to a date in a human-readable format? If so, what is the difference to PATDOB and ADMDATE, then?

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

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')  

JoshB
Quartz | Level 8

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;
PGStats
Opal | Level 21

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;
PG
FreelanceReinh
Jade | Level 19

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.

 

  • You bother to format variable BIRTDATE nicely, although this variable is not kept (hence dropped) anyway, so that the assigned format will never be effective.
  • It looks like variable PATDOB takes over from BIRTDATE. If it's just a change of names, you can use a RENAME statement (or RENAME= dataset option) to achieve this more easily.
  • It's a bit odd that neither the just created numeric date variable PATDOB (patient's date of birth, I guess) is used in the calculation of PATAGE (presumably patient's age), nor the numeric date variable ADMDATE. Instead, you use two seemingly similar variables N_PATDOB and N_ADMDATE. Does the "N_" prefix, by any chance, stand for "numeric", i.e. SAS date value as opposed to a date in a human-readable format? If so, what is the difference to PATDOB and ADMDATE, then?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 1047 views
  • 1 like
  • 5 in conversation