I have been messing around with this for nearly 20 minutes now and looking up several other threads. I am sure you experienced SAS users are about done with date questions, but can some explain what is wrong with my code?
Data BMI_DOB;
Set BMI_year;
DOB = INPUT(catx(DOB_M, DOB_Y), date7.);
format DOB date7.;
run;
Why is it converting them to character values rather than dates?
22 GOPTIONS ACCESSIBLE;
23 Data BMI_DOB;
24 Set BMI_year;
25 DOB = INPUT(catx(DOB_M, DOB_Y), date7.);
26 format DOB date7.;
27 run;
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
25:19
NOTE: Invalid argument to function INPUT at line 25 column 8.
ID=1 Gender=2 DOB_M=9 DOB_Y=1981 Race=4 Year=1997 Height=67 Weight=145 BMI=22.707730007 DOB=. _ERROR_=1 _N_=1
NOTE: Invalid argument to function INPUT at line 25 column 8.
ID=1 Gender=2 DOB_M=9 DOB_Y=1981 Race=4 Year=1998 Height=67 Weight=150 BMI=23.490755179 DOB=. _ERROR_=1 _N_=2
NOTE: Invalid argument to function INPUT at line 25 column 8.
ID=1 Gender=2 DOB_M=9 DOB_Y=1981 Race=4 Year=1999 Height=67 Weight=150 BMI=23.490755179 DOB=. _ERROR_=1 _N_=3
NOTE: Invalid argument to function INPUT at line 25 column 8.
ID=1 Gender=2 DOB_M=9 DOB_Y=1981 Race=4 Year=2000 Height=68 Weight=160 BMI=24.325259516 DOB=. _ERROR_=1 _N_=4
NOTE: Invalid argument to function INPUT at line 25 column 8.
ID=1 Gender=2 DOB_M=9 DOB_Y=1981 Race=4 Year=2001 Height=67 Weight=163 BMI=25.526620628 DOB=. _ERROR_=1 _N_=5
NOTE: Invalid argument to function INPUT at line 25 column 8.
- Your using CATX() function with in appropriate arguments. CATX(delimiter, item1,item2....) first argument is treated as delimiter. You just need CATS() instead.
- SAS will automaticallly convert numeric values to character with best. format if arguments to CAT functions are numeric.
- Notes are generated because values and format for INPUT() function doesn't match.
If you want to suppress this kind of notes then don't print them in log by setting options errors=0;
Since you have month and year only the best way is to use MDY() function, if you don't have day value simply put some dummy and use the format of month and year in which you need.
data want;
set have;
want=mdy(dob_m,01,dob_y);
format want monyy7.;
run;
I should add so you don't have to search the code that DOB_M is a numeric value 1-12 representing Month and DOB_Y is a 4 character numeric value representing year.
Are you after this?
data have;
do month=1 to 12;
year=2018;
output;
end;
run;
data want;
set have;
want=input(cats(year,month),yymmn6.);
format want date9.;
run;
The first argument to the catx function is a separator string to be inserted between concatenated parts. DOB_M being the separator, that leaves only DOB_Y as a string to be concatenated; DOB_M will not be used.
- Your using CATX() function with in appropriate arguments. CATX(delimiter, item1,item2....) first argument is treated as delimiter. You just need CATS() instead.
- SAS will automaticallly convert numeric values to character with best. format if arguments to CAT functions are numeric.
- Notes are generated because values and format for INPUT() function doesn't match.
If you want to suppress this kind of notes then don't print them in log by setting options errors=0;
Since you have month and year only the best way is to use MDY() function, if you don't have day value simply put some dummy and use the format of month and year in which you need.
data want;
set have;
want=mdy(dob_m,01,dob_y);
format want monyy7.;
run;
Hello @SuryaKiran You wrote-- "The log will show the notes because your are trying to concatenate numeric values, so SAS will automaticallly convert numeric values to character with best. format"
No, cat family of functions does not write any such auto conversion notes in the sas log.
And only the best way is to use MDY() function?
Wait until what the OP wants in his/her final result before assuming what is the best way although mdy is very straight forward, that I completely agree.
Nevertheless, we are not sure of OP's expected output-
should it revert to first of month, end or whatever, does that OP want a resulting character? OP needs to provide more info
Agree, thanks for pointing that out @Allaluiah. Although SAS will automatically converts with best. format no notes is generated. Probably the notes is generated by invalid arguments to INPUT() function.
@SuryaKiran and @Allaluiah It's very trivial, the question, the discussion about autoconversion.etc imo. Best bet is to test and confirm . 🙂
There are some functions/concepts like within hash/app that do not auto convert and no notes but just an incorrect output and error. However that is something beyond the scope of this thread anyway
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.