BookmarkSubscribeRSS Feed
Xinhui
Obsidian | Level 7

Hello There

My date variable is present like 20120317, I tried the code "fomate date yymmdd8.;" hoever, there is a error occurs as " There was a problem with the format so BEST. was used." .

 

Please let me know how to convert the 20120317 to yymmdd8.

Thanks advance.

 

 

2 REPLIES 2
art297
Opal | Level 21

Try:

data have;
  input date;
  cards;
20120317
;
run;

data want (drop=_:);
  set have (rename=(date=_date));
  format date yymmdd8.;
  date=input(put(_date,8.),yymmdd8.);
run;

Art, CEO, AnalystFinder.com

 

ballardw
Super User

Your current variable is apparently a simple numeric with the value 20120317. So conversion would look like:

 

data want;
   set have;
   datevar = input(put(datevar,f8. -L),yymmdd10.);
   format datevar date9.; /* to show the FORMAT is working*/
run;

use whatever format that you want.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 420 views
  • 0 likes
  • 3 in conversation