DATA Step, Macro, Functions and more

Unknown dates

Reply
Occasional Contributor
Posts: 9

Unknown dates

I have data like

20170822,

NK/NK/2017        how i can convert data into date9 format...?

Respected Advisor
Posts: 4,736

Re: Unknown dates

To what date would you expect the string NK/NK/2017 to get resolved? 01Jan2017? ...or something else?

Occasional Contributor
Posts: 9

Re: Unknown dates

I want that variable in date9. Format,
Trusted Advisor
Posts: 1,837

Re: Unknown dates

@BNreddy, pay attention:

       the given date 20170822 when displayed in date9. format will look like: 22AUG2017.

 

        when given date is NK/NK/2017 - what do you want to display as DAY and what as MONTH ?

        NK is not numeric valid DAY and not a valid MONTH.

         Your answer to @Patrick is not clear.

Occasional Contributor
Posts: 9

Re: Unknown dates

In one variable i want dates like

 

22aug2017

Nk/NK/2017

23aug2018

Occasional Contributor
Posts: 9

Re: Unknown dates

No it should be NK/NK/2017 only

Super User
Posts: 10,209

Re: Unknown dates


@BNreddy wrote:

No it should be NK/NK/2017 only


Then you can only store this data-crap as text, not as SAS dates.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Valued Guide
Posts: 557

Re: Unknown dates

Not clear what you have and what you need.

 

"NK/NK/2017" is not a date in any calendar i have seen so far.

Occasional Contributor
Posts: 9

Re: Unknown dates

Posted in reply to andreas_lds

NK means unknown date values i want present all values in one variable ,for more information please find below variable start data

 

Startdate

07-AUG-2017

11-AUG-2017

08-AUG-2017

NK NK 2018

NK NK NK

07-AUG-2017

 

Super User
Posts: 10,209

Re: Unknown dates


@BNreddy wrote:

NK means unknown date values i want present all values in one variable ,for more information please find below variable start data

 

Startdate

07-AUG-2017

11-AUG-2017

08-AUG-2017

NK NK 2018

NK NK NK

07-AUG-2017

 


AND WHAT SHOULD BE USED IN PLACE OF 'NK' FOR MONTH AND DAY???

A SAS date ALWAYS(!!!) needs a day and month, period. It describes exactly one existing day of a year.

And NK NK NK is of course totally unusable, but there you could at least create a valid missing value.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Occasional Contributor
Posts: 9

Re: Unknown dates

Posted in reply to KurtBremser

I need to present it as NK/NK/2017 in date variable if i converted into date9. the NK will become blank i want it as NK/NK/2017

Super User
Posts: 10,209

Re: Unknown dates


@BNreddy wrote:

I have data like

20170822,

NK/NK/2017        how i can convert data into date9 format...?


You can't, as NK/NK/2017 is not a date. I don't know of a day NK in any calender system I can think of, and NK isn't a month either.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Trusted Advisor
Posts: 1,837

Re: Unknown dates

[ Edited ]
Posted in reply to KurtBremser

I understand that your input date si a char type,

with normal date in a format of yyyymmdd, then you can try do:

length new_date $10;
test_date = input(date, ?? yymmdd8.). if test_date = . then new_date = date; else new_date = put(date,date9.);
drop test_date;
Occasional Contributor
Posts: 9

Re: Unknown dates

Thank you very much Sir..

 

Ask a Question
Discussion stats
  • 13 replies
  • 192 views
  • 1 like
  • 5 in conversation