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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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