Hi SAScommunity!
Could you please advise me how to convert '20 February 2014 09:40:56' (char $200) to a SAS date format.
I have tried the following:
data alldata1;
set alldata;
date_a = input(strip(creation_date), datetime. ); /*where creation_date=20 February 2014 09:40:56 (char $200 format)*/
format date_a datetime.;
run;
But I then get the following error:
NOTE: Invalid argument to function INPUT at line 11441 column 12.
....
NOTE: Mathematical operations could not be performed at the following places.
Did you ask this just the other day?
Did you ask this just the other day?
Thank you Data_null_, it worked like a charm! :smileygrin: :smileygrin: :smileygrin:
Nope, although I have been asking quite a lot of questions regarding time,dates etc. the last week. The data I'm working with at this point is mostly involving the date of events taking place .
This is the thread I was thinking of https://communities.sas.com/message/197837#197837
Just a last question for the day about time and dates:
I have have that y=20FEB14:09:40:56 (datetime. format at this point).
When I try to extract the month and year (I want a date returned consisting of only the month and year of this y date) , then I get an error, I'm sure it is only a format error (PS I'm trying to study the formats this last week ).
This is what I got:
data alldata;
set alldata;
y = input(creation_date,nldatm32.);
x=input(Amount,best4.);
appMonth = PUT(y,16.);
format y datetime.;
format appMonth $monyy7.;
run;
it gives the following error: NOTE 484-185: Format $MONYY was not found or could not be loaded.
And gives appMonth a value of 1 (for all observations).
When I try month(appMonth) it gives an error as well (NOTE: Invalid argument to function MONTH). Hence I reckon that it must be some format error.
You need to learn about SAS date and datetime variables. Once you create Y in your example program you have a SAS datetime. You can get out just the date with the DATEPART part function then apply MONTH to that. You don't need PUT(Y,16.) that gets you nothing you can use. Visit the online documentation first.
Try with this informat
anydtdtm27.
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 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: