BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rakeshvvv
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
AMSAS
SAS Super FREQ

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 ;




View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

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.

AMSAS
SAS Super FREQ

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 ;




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
  • 2 replies
  • 3828 views
  • 1 like
  • 3 in conversation