BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
wlierman
Lapis Lazuli | Level 10

I have a data set that has a field          Var                  Type            Length              Format                     Informat

                                                     BR_DOSBEG      numeric              8              DateTime22.3         DateTime22.3

 

and representative values look like:         23MAR2016:00:00:00.000

                                                                 15FEB2015:00:00:00.000

                                                                 16FEB2015:00:00:00.000       

                                                                                 . . .

 

The code that I have tried follows:

 

Data parts;
    Set stgcoc99.COC_PMCA_clms (keep= DOSdate BR_DOSBEG);
Format DOSdate date9.;
DOSdate=datepart(input(BR_DOSBEG,datetime22.3;
run;

I have looked at prior posts and solutions on this question. In fact, a solution by kurt_bremser (below with one actual value from my data) works great:

 

 

data _null_;
BR_DOSBEG="23MAR2016:00:00:00.000    (this is a value from my data as well as column name)
format newdate date9.;
newdate=datepart(input(BR_DOSBEG,datetime22.3));
put newdate=;
run;

However, I haven't been able to successfully apply that approach in my data set. 

The last ERROR that was shown in the log was:

 

                                                                  DOSdate=datepart(BR_DOSBEG,datetime22.3));   

                                                                                                                         -----------------

                                                                                ERROR 386-185   Expecting an arithmetic expression                                   

 

Your help/tips are greatly appreciated.  I am using SAS v.9.

wlierman

 

                                                                     

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

The DATEPART only takes a single parameter, the variable. 
If you look at the previous function it's actually two functions nested, INPUT() and DATEPART. 

 

dosdate = datepart(br_dosbeg);

View solution in original post

4 REPLIES 4
cau83
Pyrite | Level 9

DATEPART() only requires one argument. What you're using with the format as the 2nd argument was part of the INPUT function in that other example. Just use: 

DOSdate=datepart(BR_DOSBEG);   
Reeza
Super User

The DATEPART only takes a single parameter, the variable. 
If you look at the previous function it's actually two functions nested, INPUT() and DATEPART. 

 

dosdate = datepart(br_dosbeg);
kiranv_
Rhodochrosite | Level 12

Date in your table is already in datetime22.3 and all you need do is use datepart as shown below

 

data have;
input BR_DOSBEG:DateTime22.3;
format  BR_DOSBEG:DateTime22.3;
datalines;
23MAR2016:00:00:00.000
15FEB2015:00:00:00.000
16FEB2015:00:00:00.000
;

data want;
set have;
format newdate date9.;
newdate=datepart(BR_DOSBEG);
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1679 views
  • 0 likes
  • 5 in conversation