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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 907 views
  • 0 likes
  • 5 in conversation