BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mjheever
Obsidian | Level 7

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.

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

6 REPLIES 6
data_null__
Jade | Level 19

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
mjheever
Obsidian | Level 7

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.

mjheever
Obsidian | Level 7

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.



data_null__
Jade | Level 19

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.

Barnipaz
Obsidian | Level 7

Try with this informat

anydtdtm27.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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