DATA Step, Macro, Functions and more

How to convert string variable to date?

Reply
SAS Employee o_p
SAS Employee
Posts: 8

How to convert string variable to date?

[ Edited ]
data have;
yearmonth='200801';
run;

What is the best way to have same variable as date?

I mean it must be shown as 200801 again, but in date format.

 

Thanks,

 

 

Trusted Advisor
Posts: 1,931

Re: How to convert string variable to date?

Is this what you are looking for?

yearmonth2=input(yearmonth,yymmn6.);

Super User
Posts: 11,343

Re: How to convert string variable to date?

Posted in reply to PaigeMiller

And use

Format yearmonth2 yymm6.;

for display.

Trusted Advisor
Posts: 1,931

Re: How to convert string variable to date?

Good point, @ballardw!

SAS Employee o_p
SAS Employee
Posts: 8

Re: How to convert string variable to date?

Posted in reply to PaigeMiller
data have;
yearmonth='200801';
yearmonth2=input(yearmonth,yymmn6.);
Format yearmonth2 yymmn6.;
run;

That's OK. Smiley Happy

 

 

Valued Guide
Posts: 860

Re: How to convert string variable to date?

data have;
yearmonth='200801';
run;

data want;
format date yymmn6. date2 mmddyy10.;
set have;
date = input(put(yearmonth,$6.),yymmn6.);
date2 = intnx('month',date,0,'end');
run;

Ask a Question
Discussion stats
  • 5 replies
  • 195 views
  • 0 likes
  • 4 in conversation