BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

I have a dateTime as numeric as 06oct22:10:03, when I put datepart function to get the datepart of the variable, the time function still exists in the reuslt.

Date1 = put(datepart(date2,date9.)

Can someone help me with this?

Thanks,

blue blue

Blue Blue
3 REPLIES 3
ballardw
Super User

LOG. Read it.

If you actually submit that code you are missing a )

40   data example;
41     x='06oct22:10:03'dt;
42     y=put(datepart(x,date9.);
                        ------
                        386
                        76
ERROR 386-185: Expecting an arithmetic expression.

ERROR 76-322: Syntax error, statement will be ignored.

43   run;

Should be:

44   data example;
45     x='06oct22:10:03'dt;
46     y=put(datepart(x),date9.);
47   run;

The result is 06OCT2022.

Or use a different FORMAT:

data example;
  x='06oct22:10:03'dt;
  y=put(x,dtdate9.);
run;

The DTDATE format displays a datetime with just the DATE9 equivalent portion.

 

So if your code isn't working you either have an issue with the values, the syntax or possibly both.

Although I question a need for that creation of a character value for dates. They don't sort well, at least not in Date9 format, cause extra work if you need to compare to an actual date value elsewhere, cannot be used in any of the date functions like Intnx or Intck, use formats to modify group creation for analysis, reporting or graphing.

GN0001
Barite | Level 11
Hello team, I have not tested it. Please give me some time to test it. Blue berry
Blue Blue

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!
How to Concatenate Values

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.

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
  • 3 replies
  • 917 views
  • 4 likes
  • 3 in conversation