BookmarkSubscribeRSS Feed
nevennett
Fluorite | Level 6

Hi, 

I'm using SAS on demand and I'm struggling to change a numeric variable to a SAS date. 

 

My numeric variable is SurgStart which has format best12. and informat best32. It contains 8 digits that represents YYYYMMDD

 What I want to do is changed SurgStart e.g.20140410 to become the date 2014 04 10 so I can then do time series analysis. 

My code is:

data ab1;

set ab;

SurgDate=input(put(SurgStart, best12.), yyyymmdd.);
format SurgDate date8.;
run;

 

This doesn't work. 

 

Please help!

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

You're close 🙂 Use the Best8. Format and the appropriate yymmdd8. Informat

 

data _null_;
    SurgStart=20140410;
    SurgDate=input(put(SurgStart, best8.), yymmdd8.);
    put SurgStart= SurgDate= date8.;
run;

 

ErikLund_Jensen
Rhodochrosite | Level 12

Hi @nevennett 

 

Try this instead:

 

SurgDate=input(put(SurgStart, 8.), yymmdd8.);
anushreebiotech
Obsidian | Level 7

Hi,

 

data have;
input Surgstart;
datalines;
20140410
;
run;

data want;
set have;
SurgDate=Input( Put( Surgstart, 8.), Yymmdd10.);
format SurgDate Yymmdd10.;
run;

nevennett
Fluorite | Level 6

Thanks everyone for answering my question. A combination of the responses seems to have done the trick:

 

data ab1;
set ab;
SurgDate=input(put(SurgStart, 8.),yymmdd8.);
format SurgDate yymmdd8.;
run;

Thank you so much!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 5 replies
  • 1518 views
  • 4 likes
  • 5 in conversation