SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

How to create date variable

Reply
Frequent Contributor
Posts: 89

How to create date variable

I got cmstdtc values like
            2003
            2009
            2009
           Aug 2013
          Aug-12-2014

i need to substract or add this dates with another dates which are full length dates
Aug-12-2014
June-12-2014
Apr-12-2014

Frequent Contributor
Posts: 115

Re: How to create date variable

Well well, Have i not understood your question clearly or could you explain better please. Are you trying to extract date from the top 5 obs in your sample and then add or minus with other dates?It's difficult to understand what you are trying to achieve. Please provide your sample(have) dataset and (want) dataset.

Frequent Contributor
Posts: 89

Re: How to create date variable

I have


2003

2007
2008
AUG-2009
AUG-2003
SEP-12-2009 and
iwant
i want results like which day the patient came to the visit
7
10
15
16
10

Super User
Posts: 17,899

Re: How to create date variable

So if you have 2003 what date do you want to map that to?

Same for 2007/2008?

And if you have month & year what are you assuming the day is? Can you assume the first, last or should you assume middle of the month?

Frequent Contributor
Posts: 89

Re: How to create date variable

For anyday within a month

Super User
Posts: 5,260

Re: How to create date variable

You are still way to vague.

Show exactly what kind of output you desire based on input data, and try to explain in more words why/how.

Data never sleeps
Frequent Contributor
Posts: 83

Re: How to create date variable

If first day of the month is OK, try this code.    Jim

data;

input  dat  $20.;

len=length(dat);     monyr='          ';

if len=4 then do;

  ndat=input(dat,4.); 

  date=mdy(1,1,ndat);

end;

if len=8 then date=input(dat,monyy10.);

if len gt 8 then do;

   mon=scan(dat,1);  day=scan(dat,2);  yr=scan(dat,3);

   *monyr=mon||yr;

   substr(monyr,1,3)=mon;  substr(monyr,4,4)=yr;

   date=input(monyr,monyy10.);

   nday=input(day,2.);  date=date+nday-1;

end;

format date  mmddyy10.;

cards;

2003

2007

2008

AUG-2009

AUG-2003

SEP-12-2009

proc print;    run;

Respected Advisor
Posts: 3,777

Re: How to create date variable

In clinical trials data processing there is "always" a document that provides information on how incomplete dates (or anything else) should be imputed.  You should read that.

Perhaps something like this.

01-JUL-year when you have only the year.

15-mon-year when you have only month and year.

Sometimes the imputation is slightly different if the date is a start versus an end date.

The point is, the answer to the imputation is in the documentation for the analysis and you already have that.

Ask a Question
Discussion stats
  • 7 replies
  • 498 views
  • 0 likes
  • 6 in conversation