Help using Base SAS procedures

Char $200 format to SAS date format

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

Char $200 format to SAS date format

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.


Accepted Solutions
Solution
‎02-24-2014 07:54 AM
Respected Advisor
Posts: 3,799

Re: Char $200 format to SAS date format

Did you ask this just the other day?

data _null_;
  
x = '20 February 2014 09:40:56';
   y = input(x,
nldatm32.);
   put y=;
   format y datetime.;
  
run;

17         data _null_;
18            x = '20 February 2014 09:40:56';
19            y = input(x,nldatm32.);
20            put y=;
21            format y datetime.;
22            run;

y=20FEB14:
09:40:56

View solution in original post


All Replies
Solution
‎02-24-2014 07:54 AM
Respected Advisor
Posts: 3,799

Re: Char $200 format to SAS date format

Did you ask this just the other day?

data _null_;
  
x = '20 February 2014 09:40:56';
   y = input(x,
nldatm32.);
   put y=;
   format y datetime.;
  
run;

17         data _null_;
18            x = '20 February 2014 09:40:56';
19            y = input(x,nldatm32.);
20            put y=;
21            format y datetime.;
22            run;

y=20FEB14:
09:40:56
Contributor
Posts: 42

Re: Char $200 format to SAS date format

Posted in reply to data_null__

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 Smiley Happy.

Respected Advisor
Posts: 3,799

Re: Char $200 format to SAS date format

This is the thread I was thinking of https://communities.sas.com/message/197837#197837

Contributor
Posts: 42

Re: Char $200 format to SAS date format

Posted in reply to data_null__

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 Smiley Wink ).

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.



Respected Advisor
Posts: 3,799

Re: Char $200 format to SAS date format

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.

Contributor
Posts: 33

Re: Char $200 format to SAS date format

Try with this informat

anydtdtm27.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 564 views
  • 4 likes
  • 3 in conversation