How to read unknown date and month in dataset

Reply
Contributor
Posts: 32

How to read unknown date and month in dataset

HI,

Could you any one help me how to read the date for the below program. and i want first dataset default date as 01and default month as 07, and second dataset default date as 09 and month as 01; and want it by two dataset

data sam;

Input date$;

Datalines;

UUUNK2013

UUUNK2012

UUUUU2013

   UU2013

     2013

01052013

run;

data another;

Input date$12.;

datalines;

UU-UNK-2013

UU-UNK-2012

UU-UUU-2013

UN-UNK-2013

UU-          2013

                 2013

       UNK-2013

05-MAY-2013

06-AUG-2013

07-MAR-2013

run;

Super Contributor
Posts: 282

Re: How to read unknown date and month in dataset

Hi,

Do you want the dates stored in the form of a SAS date, i.e., numeric?

Regards,

Amir.

Contributor
Posts: 32

Re: How to read unknown date and month in dataset

no i want it as  charcter. Take that datalines as dataset, UU as missing dat which should replace with default date 07, and UNK as mssing month it should be Aug or some month

Super Contributor
Posts: 282

Re: How to read unknown date and month in dataset

Hi,

Based on the sample data provided, I have created the code shown below.

I'm not sure what day of month you wanted, as I can see in the posts 01, 07 & 09.

If this is still not what you require, then please post the results you want for the input you have given.

data sam(keep=date);

  length date $8;

  input text $char9.;

  if length(strip(text)) ne 8 or compress(text,,'d') ne '' then

  do;

    yyyy=substr(strip(text),length(strip(text))-3);

    date=cats('01','07',yyyy);

  end;

  else

    date=strip(text);

  datalines;

UUUNK2013

UUUNK2012

UUUUU2013

   UU2013

     2013

01052013

;

data another(keep=date);

  length date $11;

  input text $char21.;

  if length(strip(text)) ne 11 or strip(text)=:'U' then

  do;

    yyyy=substr(strip(text),length(strip(text))-3);

    date=cats('01-AUG-',yyyy);

  end;

  else

    date=strip(text);

  datalines;

UU-UNK-2013

UU-UNK-2012

UU-UUU-2013

UN-UNK-2013

UU-          2013

                 2013

       UNK-2013

05-MAY-2013

06-AUG-2013

07-MAR-2013

;

Regards,

Amir.

Super Contributor
Posts: 282

Re: How to read unknown date and month in dataset

Hi,

If you do want to store the dates as numerics, the following might help:

data sam(keep=date);

Input date anydtdte9. @;

if date=. then

do;

  input @1 text $char9.;

  yyyy=substr(strip(text),length(strip(text))-3);

  date=mdy(7,1,yyyy);

end;

Datalines;

UUUNK2013

UUUNK2012

UUUUU2013

   UU2013

     2013

01052013

run;

data another(keep=date);

Input date anydtdte11. @;

if date=. then

do;

  input @1 text $char21.;

  yyyy=substr(strip(text),length(strip(text))-3);

  date=mdy(7,1,yyyy);

end;

datalines;

UU-UNK-2013

UU-UNK-2012

UU-UUU-2013

UN-UNK-2013

UU-          2013

                 2013

       UNK-2013

05-MAY-2013

06-AUG-2013

07-MAR-2013

run;

Regards,

Amir.

Ask a Question
Discussion stats
  • 4 replies
  • 699 views
  • 0 likes
  • 2 in conversation