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
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);
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);
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);
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;
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about manipulating dates.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.