Hi All,
Can someone suggest me method to convert partial date in ISO8601 date format.Please see the below examples.
UN/JAN/2017
UN/NOV/2017
UN/APR/2017
UN/UN/2017
Thanks in Adavance
Here's an example, I broke it down into individual steps to help explain. You want to convert your date value into a SAS date value and then apply a ISO8601 format to it
data dates ;
length cDate $9 ;
/* read in the character date value */
input charDate $11. ;
/* break the day month & year into seperate parts */
cDay=scan(charDate,1,"/") ;
cMonth=scan(charDate,2,"/") ;
cYear=scan(charDate,3,"/") ;
/* Change any UN values to 01 (day) JAN (month) */
if cDay="UN" then
cDay="01" ;
if cMonth="UN" then
cMonth="JAN" ;
/* Create a character value in the format DDMONYYYY e.g. 10DEC2018 */
cDate=trim(cDay)!!trim(cMonth)!!trim(cyear) ;
/* Convert character value to a SAS Date Value */
sasDate=inputn(cDate,"date9.") ;
/* Create a character value from the SAS date value using a ISO 8601 SAS format */
iso8061Date=putn(sasDate,"B8601DA.") ;
cards ;
UN/JAN/2017
UN/NOV/2017
UN/APR/2017
UN/UN/2017
;
run ;
Make up a rule for replacing the 'UN' parts with default or specially calculated values. After replacing, and removing the slashes with compress(), you can use the date9. informat and assign the e8601da10. format for display.
Here's an example, I broke it down into individual steps to help explain. You want to convert your date value into a SAS date value and then apply a ISO8601 format to it
data dates ;
length cDate $9 ;
/* read in the character date value */
input charDate $11. ;
/* break the day month & year into seperate parts */
cDay=scan(charDate,1,"/") ;
cMonth=scan(charDate,2,"/") ;
cYear=scan(charDate,3,"/") ;
/* Change any UN values to 01 (day) JAN (month) */
if cDay="UN" then
cDay="01" ;
if cMonth="UN" then
cMonth="JAN" ;
/* Create a character value in the format DDMONYYYY e.g. 10DEC2018 */
cDate=trim(cDay)!!trim(cMonth)!!trim(cyear) ;
/* Convert character value to a SAS Date Value */
sasDate=inputn(cDate,"date9.") ;
/* Create a character value from the SAS date value using a ISO 8601 SAS format */
iso8061Date=putn(sasDate,"B8601DA.") ;
cards ;
UN/JAN/2017
UN/NOV/2017
UN/APR/2017
UN/UN/2017
;
run ;
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.