DATA Step, Macro, Functions and more

correct SAS informat for dates of the form YYYYMMDD?

Accepted Solution Solved
Reply
Contributor
Posts: 44
Accepted Solution

correct SAS informat for dates of the form YYYYMMDD?

I have dates stored in a numeric variable of the form YYYYMMDD, with no separator between the day month and year parts. An example is 20090629. I wish to store it in a SAS date field. I am using the following line:

xPolSD = Input(PolSD,yymmddn8.);

but which is giving me an error. I have also tried using

xPolSD = Input(PolSD,yymmdd8.);

which also gives an error.

What is the correct SAS informat to use in this instance?


Accepted Solutions
Solution
‎01-28-2013 08:19 AM
Trusted Advisor
Posts: 1,131

Re: correct SAS informat for dates of the form YYYYMMDD?

Thank you for your feedback.

hope the below code will be more understandable Smiley Happy

data have;

    input date $;

    new_date=input(date,yymmdd8.);

    format new_date date9.;

cards;

20090629

;

run;

Thanks,

Jagadish

Thanks,
Jag

View solution in original post


All Replies
Super User
Posts: 5,260

Re: correct SAS informat for dates of the form YYYYMMDD?

You need to put your date first, so it becomes a string.

Data never sleeps
Trusted Advisor
Posts: 1,131

Re: correct SAS informat for dates of the form YYYYMMDD?

As @Linus rightly suggested please convert the numeric value to character and try the below code

data have;

    date="20090629";

    new_date=input(date,yymmdd8.);

    format new_date date9.;

run;

Thanks,

Jagadish

Thanks,
Jag
Super User
Posts: 5,260

Re: correct SAS informat for dates of the form YYYYMMDD?

I think you are confusing Mediaeval by treating the date as a constant, not as a columnSmiley Wink

Data never sleeps
Solution
‎01-28-2013 08:19 AM
Trusted Advisor
Posts: 1,131

Re: correct SAS informat for dates of the form YYYYMMDD?

Thank you for your feedback.

hope the below code will be more understandable Smiley Happy

data have;

    input date $;

    new_date=input(date,yymmdd8.);

    format new_date date9.;

cards;

20090629

;

run;

Thanks,

Jagadish

Thanks,
Jag
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 335 views
  • 6 likes
  • 3 in conversation