Am not able to convert character text to a SAS date, apologies for the simple request:
Data to be converted are "Mark_App_s" character of length 12.
Date sample
Mark_App_s
11/20/2001
09/05/2017
06/06/2017
10/31/2017
Code sample is :
Data App_2 ;
set App_1 ;
Mark_App = input(Mark_App_s, yymmdd10.) ;
format Mark_App mmddyy10.;
run ;
Thanks !
You can't change type of a variable and there is no a date type.
In your code Mark_app will be a numeric type. The format defines that it is a date and how to display it.
The input variable - Mark_app_s - is a char type variable.
The only way to "change" variable type is by recreating it:
data want;
set have (rename=(numvar=char));
numvar = input(char, <informat>);
run;
The yymmdd10. informat would be used to read data that starts with the year such as 2001/11/20.
You may sometimes have to use something like input(strip(variable),<informat>) if the character variable has leading spaces so that the informat starts reading where the data actually begins.
Thanks, I was using the correct INFOMAT, (mmddyy10.), very sorry I just typed it wrong (above), and I have stripped the leading and trailing characters, and have also set the length of the character variable "Mark_App_s " to $12.
So here is a data sample:
Mark_App_s
11/20/2001
09/05/2017
08/30/2017
06/06/2017
10/31/2017
01/23/2004
and here is the code
Data App_2 ;
set App_1 ;
Mark_App = input(Mark_App_s, mmddyy10.) ;
format Mark_App mmddyy10.;
run ;
And this code does not change the character variable to a date variable.
You can't change type of a variable and there is no a date type.
In your code Mark_app will be a numeric type. The format defines that it is a date and how to display it.
The input variable - Mark_app_s - is a char type variable.
The only way to "change" variable type is by recreating it:
data want;
set have (rename=(numvar=char));
numvar = input(char, <informat>);
run;
Note about the solution, the difficulty was caused by hidden characters in the variable "Mark_App_s ", which was imported from an online database. Prior to implementing the above solution, I had to parse the variable using a SUBSTRING into MM, DD, YYYY components, Then tried converting each to a numeric variable. If it would not convert using an INPUT function, that indicated there were hidden characters, and I continued to use the SUBSTRING function until the numeric conversion method worked. Only then could the
Mark_App_d = mdy(Month_2,Day,Year)
function be used to convert the character variables (Month_2,Day,Year) to a SAS Date.
Thanks again for your assistance !
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.