Is it possible to use a macro definition as an argument in a function? I've used them for filenames and such (e.g., GET FILE !Path + "filename.sav" ), but can't seem to figure out how to use them to insert, say, dates into various functions. E.g.,
DEFINE !EndDate() '1,31,2013' !ENDDEFINE.
if (todaydate LE date.mdy(!EndDate)) testvar=1. I would think the result would be "if (todate LE date.mdy(1,31,2013)) testvar=1." but it just errors out. Thank you. Anthony Cagle (Dr.) University of Washington |
Administrator
|
LOSE THE QUOTES!!!
Please see the very helpful SET MPRINT ON. Hard to debug blindfolded!
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Administrator
|
In reply to this post by anthony cagle
"SET mprint on" is useful for figuring out what is going wrong with a macro. In the case of your macro, it showed me that you don't want the quotes in your macro definition. Try this:
data list list / todaydate (date11). begin data 29-Jan-2013 30-Jan-2013 31-Jan-2013 1-Feb-2013 2-Feb-2013 3-Feb-2013 end data. DEFINE !EndDate() 1,31,2013 !ENDDEFINE. numeric testvar(f1). *set mprint on. compute testvar = (todaydate LE date.mdy(!EndDate)). *set mprint off. list. OUTPUT: todaydate testvar 29-JAN-2013 1 30-JAN-2013 1 31-JAN-2013 1 01-FEB-2013 0 02-FEB-2013 0 03-FEB-2013 0 Number of cases read: 6 Number of cases listed: 6 Note too that I changed your IF to a COMPUTE so that cases where the condition is not met are assigned a value of 0. Your IF had them as SYSMIS. For variables that are meant to flag the truth of some condition, I think it makes a lot more sense to have 1=True and 0=False (rather than MISSING=False). HTH.
--
Bruce Weaver bweaver@lakeheadu.ca http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." PLEASE NOTE THE FOLLOWING: 1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. 2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/). |
Free forum by Nabble | Edit this page |