Hello,
I need help converting numeric variable to a usable SAS date variable.
This is a snippet of the data:
Date1
19370215
19370215
19370215
19700210
and I want the data to look like this
Date2
1937/02/15
1937/02/15
1937/02/15
1970/02/10
So I am using this code:
data want;
set have;
Date2 = Input( Put( Date1, z8.), mmddyy10.);
run;
But I keep getting this note
NOTE: Invalid argument to function INPUT at line 30 column 14.
And Date2 column is completely blank.
Any help?
Your input dates are in the form year-month-day (yymmdd), not month-day-year (mmddyy). So your informat just needed adjusting. Then a format statement will make date2 in the form YYYY/MM/DD.
data want;
set have;
format date2 yymmdds10.;
date2 = input(put(date1, z8.), yymmdd8.);
run;
So I implemented those changes but the Date2 column is still blank and I still get the warning:
NOTE: Invalid argument to function INPUT at line 30 column 14.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
Any advice?
Show us the log, so we can see the code as it appears in the log, plus ALL Notes, WARNINGS and ERRORs.
Here is the log:
NOTE: Invalid argument to function INPUT at line 31 column 14.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
Date1=19880202 Date_Adjudication=20191011 Claim_Type=M
Date_Begin_Service_Header=10/01/2019 Date_Billed=10/04/2019 Date_End_Service_Header=10/01/2019 Date_of_Service_YYYYMM=201910
Date_Begin_Service_Detail=10/01/2019 Date_End_Service_Detail=10/01/2019 Date_of_Service_YYYYMM_DTL=201910
Date_Birth_Recipient_RID=02/02/1988 Date_Death_Recipient=12/31/9999 Index=B Diag_Code=N179 I_Primary_Diag=Y Birth_DATE=. _ERROR_=1
_N_=20
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
20798726 at 31:14
NOTE: There were 20798726 observations read from the data set TABLE.
NOTE: The data set TABLE has 20798726 observations and 18 variables.
NOTE: DATA statement used (Total process time):
real time 3:26.59
cpu time 24.76 seconds
Show us the log, so we can see the code as it appears in the log, plus ALL Notes, WARNINGS and ERRORs.
28 data table;
29 set table;
30 format Birth_Date yymmdd10.;
31 Date2 = Input( Put( Date1 z8.), mmddyy10.);
32 run;
NOTE: Invalid argument to function INPUT at line 31 column 14.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
Date1=19880202 Date_Adjudication=20191011 Claim_Type=M
Date_Begin_Service_Header=10/01/2019 Date_Billed=10/04/2019 Date_End_Service_Header=10/01/2019 Date_of_Service_YYYYMM=201910
Date_Begin_Service_Detail=10/01/2019 Date_End_Service_Detail=10/01/2019 Date_of_Service_YYYYMM_DTL=201910
Date_Birth_Recipient_RID=02/02/1988 Date_Death_Recipient=12/31/9999 Index=B Diag_Code=N179 I_Primary_Diag=Y Birth_DATE=. _ERROR_=1
_N_=20
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to
missing values.
Each place is given by: (Number of times) at (Line):(Column).
20798726 at 31:14
NOTE: There were 20798726 observations read from the data set TABLE.
NOTE: The data set TABLE has 20798726 observations and 18 variables.
NOTE: DATA statement used (Total process time):
real time 3:26.59
cpu time 24.76 seconds
The PUT function has a comma between the variable name and the format.
You are still trying to read your YY,YYM,MMM numbers as if they were MM,DDY,YYY numbers.
Change the INFORMAT you are using to read the string generated by the PUT() function.
Pay attention to details.
In particular, take a close look at the informat that @mklangley uses.
Code that we post is usually tested and WORKS with the example data supplied.
Also see my notes:
data table;
/* bad idea: overwriting the input dataset */
/* if something untoward happens, your data is destroyed, and you need to recreate it */
set table;
format Birth_Date yymmdd10.;
/* is birth_date already on the dataset? */
/* if not, it will have missing values only, and cause a NOTE */
Date2 = Input( Put( Date1 z8.), mmddyy10.);
/* as already mentioned, wrong informat */
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.