BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
merveayibogan
Fluorite | Level 6

Hello, I have an excel file named crspoutput that looks like this:

 

Modelpermnoevtdatecretcarbharnrets_est
Market-Adjusted Model1002620170103-0.0193-0.02369-0.02414100
Market-Adjusted Model1002620170817-0.01316-0.01357-0.01389100
Market-Adjusted Model10104201704170.0126350.0007490.000795100

 

When I check the formats, I see that evtdate is numeric in Best12. format with len 8, how can I convert  this to a num len 8 date9. format ?

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
merveayibogan
Fluorite | Level 6

Hello, thank you very much for your response. That didn't work but this worked:


data new data;
set olddata; 
if not missing(evtdate) then do;
year = int(evtdate / 10000); 
month = int((evtdate - year * 10000) / 100); 
day = mod(evtdate, 100);
put year= month= day= evtdate=;
new_date_variable = mdy(month, day, year);

format new_date_variable date9.;
end;
run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26
evtdate1 = input(put(evtdate,8.),yymmdd8.);
format evtdate1 date9.;
--
Paige Miller
merveayibogan
Fluorite | Level 6

Hello, thank you very much for your response. That didn't work but this worked:


data new data;
set olddata; 
if not missing(evtdate) then do;
year = int(evtdate / 10000); 
month = int((evtdate - year * 10000) / 100); 
day = mod(evtdate, 100);
put year= month= day= evtdate=;
new_date_variable = mdy(month, day, year);

format new_date_variable date9.;
end;
run;

Tom
Super User Tom
Super User

Glad you got it to work.

 

But note that any value of EVTDATE that would could be split by your logic into separate year, month and day values that would also work when converted to a string using PUT() and then converted to a date value using INPUT().

 

Try it

data new data;
  set olddata; 
  if not missing(evtdate) then do;
    year = int(evtdate / 10000); 
    month = int((evtdate - year * 10000) / 100); 
    day = mod(evtdate, 100);
    new_date_variable = mdy(month, day, year);
    new_date_variable2 = input(put(evtdate,z8.),yymmdd8.);
    format new_date_variable new_date_variable2  date9.;
    put  (evtdate year month day new_date_variable new_date_variable2) (=);
  end;
run;

 

PaigeMiller
Diamond | Level 26

@merveayibogan wrote:

Hello, thank you very much for your response. That didn't work but this worked:


data new data;
set olddata; 
if not missing(evtdate) then do;
year = int(evtdate / 10000); 
month = int((evtdate - year * 10000) / 100); 
day = mod(evtdate, 100);
put year= month= day= evtdate=;
new_date_variable = mdy(month, day, year);

format new_date_variable date9.;
end;
run;


The code I posted worked for me. The whole idea of your code is to pull out the year, month and day and then recombine using the MDY function. Lots of steps compared to the two lines of code I showed.

--
Paige Miller

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 880 views
  • 0 likes
  • 3 in conversation