On running the code below I have the following error messages. Can anyone help with correcting the code
ERROR: INPUT function requires a character argument.
ERROR: Expression using greater than or equal (>=) has components that are of different data types.
%let user = xxxx;
LIBNAME mdcrd_vw TERADATA SCHEMA=xxx_vdm_view_mdcr_prd
SERVER="xxxprodp.xxxsvc.local" CONNECTION=global AUTHDOMAIN="TD_&SYSUSERID.";
%macro Zip5 (start_dt, end_dt);
PROC SQL;
DROP TABLE nfpp_trd.&user._BENE_2015_3_all;
CREATE TABLE nfpp_trd.&user._bENE_2015_3_all
(DBCREATE_TABLE_OPTS='PRIMARY INDEX(BENE_SK)') AS
SELECT DISTINCT T1.GEO_sk AS bene_zip_cd,
T1.GEO_ZIP4_CD,
T1.BENE_sk,
T2.GEO_FIPS_CNTY_CD,
t2.GEO_FIPS_STATE_CD
FROM mdcrd_vw.V2_MDCR_BENE_FCT_TRANS_HSTRY t1 LEFT JOIN
mdcrd_vw.V2_MDCR_GEO_ZIP9_CD T2 ON (T1.GEO_sk=T2.GEO_sk AND T1.GEO_ZIP4_CD=T2.GEO_ZIP4_CD)
WHERE
BENE_PTA_STUS_CD ='Y'
AND BENE_PTB_STUS_CD = 'Y'
AND BENE_CVRG_TYPE_CD = '9'
and T1.BENE_DEATH_DT = .
and T1.IDR_LTST_TRANS_FLG = 'Y'
and t1.bene_fct_efctv_dt between input(&start_dt.,date9.) and input(&end_dt.,date9.)
and t1.BENE_FCT_OBSLT_DT >=input(&start_dt.,date9.);
QUIT;
%mend zip5;
%zip5 ("01JAN2019"d, "31DEC2019"d);
Please post the whole log of the step by copy/pasting it into a window opened with this button:
Since the position of the ERROR indicator is then kept, it makes it much easier for use to spot the problem point.
@onyeajam wrote:
Attached is the log
Ah ... no?
Just copy/paste it into a code box as requested, no need for attaching anything.
Input function requires a character argument.
So, here, your first argument to INPUT is not character. What are the values of these macro variables?
and t1.bene_fct_efctv_dt between input(&start_dt.,date9.) and input(&end_dt.,date9.)
and t1.BENE_FCT_OBSLT_DT >=input(&start_dt.,date9.);
@onyeajam wrote:
Start date is 01Jan2019 and end date is 31Dec2019.
So am I changing this
&start_dt to 01jan2019
I think you have missed the point. You don't have to change the values of the macro variables. You just remove the INPUT function, as shown by @Kurt_Bremser
and t1.bene_fct_efctv_dt between input(&start_dt.,date9.) and input(&end_dt.,date9.)
and t1.BENE_FCT_OBSLT_DT >=input(&start_dt.,date9.);
This seem to be the offending parts.
Since you call the macro with date literals:
%zip5 ("01JAN2019"d, "31DEC2019"d);
which are immediately converted to numeric SAS date values, the INPUT function is not needed. It would be needed if you had omitted the trailing "d" characters that make a string a date literal.
So you can simplify the offending lines to:
and t1.bene_fct_efctv_dt between &start_dt. and &end_dt.
and t1.BENE_FCT_OBSLT_DT >= &start_dt.;
I really hate to repeat myself, but:
POST THE WHOLE LOG AS ASKED!!
You left the keyword INPUT somewhere in your code where it's not needed, but I can't tell you where without seeing the WHOLE log. I hope you get the message now.
Turn on the MPRINT option before calling the macro. That way the SAS log will reflect the SAS code that the macro generated.
options mprint;
%zip5 ("01JAN2019"d, "31DEC2019"d);
So with your original macro code and macro call you should see something like this in the log:
MPRINT(ZIP5) .... input("01JAN2019"d,date9.) and input("31DEC2019"d,date9.) and t1.BENE_FCT_OBSLT_DT >=input("01JAN2019"d,date9.);
Which is trying to execute read from a date value instead of a character string.
If you change the call to use a quoted string instead of a date literal
%zip5 ("01JAN2019", "31DEC2019");
Then the code will look like this:
MPRINT(ZIP5) .... input("01JAN2019",date9.) and input("31DEC2019",date9.) and t1.BENE_FCT_OBSLT_DT >=input("01JAN2019",date9.);
Which is valid.
Although this has been mentioned several times before, you just take out the INPUT function, and your code will work.
and t1.bene_fct_efctv_dt between &start_dt and &end_dt
and t1.BENE_FCT_OBSLT_DT >=&start_dt;
...
%zip5 ("01JAN2019"d, "31DEC2019"d);
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.