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

I'm working in DI Studio, and have trouble changing the format of a numeric variable.

My input table has a numeric variable with the format yyyymmdd. Value example: 20130531.

I need to convert it to the DATE9. format, so that it displays as 31MAY2013.

What kind of expression can I use for this?

I tried using this:

input(put(DUE_DT, yyyymmdd.),date9.)

However, the values only become blank/null.

Thanks for your time!

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

Ok, so you date values are not stored as SAS dates. Then datepart will definitely not work.

So, apart from specifying date9. on the target column, you need to transform the value, as in your initial post.

First, there is not format called yyyymmdd., it's called yymmdd.

In your case, the data is already stored in a read friendly format, so use 8. format in the put statement instead, and yymmdd8. on the input.


Data never sleeps

View solution in original post

5 REPLIES 5
ballardw
Super User

If your values are a SAS date value the statement would be: format variablename date9.;

If not then the assignment should be

 

input(put(due_dt,f8.0),yymmdd.);

The put(due_dt, yyyymmdd.) has two problems in your case, first the format would be yymmdd. , second if the value isn't a date value then your results are going to be very unpredictable, and in this case it would represent a day in the future well past the range of dates SAS will manipulate


LinusH
Tourmaline | Level 20

What you mean by convert?

Basically,  just specify the required format in target table properties.

Data never sleeps
TurnTheBacon
Fluorite | Level 6

Thanks, but if I simply specify DATE9 as the target table column format, all the values show up as " ********* ". Incompatible date formats, I think.

Incidentally, if I use the expression datepart(due_dt) and the DATE9 format in the target table, all date values display as "20AUG1960" (correct format, wrong values).

EDIT: If I force it to have the 8.0 format, the values still appear as "20130531".

LinusH
Tourmaline | Level 20

Ok, so you date values are not stored as SAS dates. Then datepart will definitely not work.

So, apart from specifying date9. on the target column, you need to transform the value, as in your initial post.

First, there is not format called yyyymmdd., it's called yymmdd.

In your case, the data is already stored in a read friendly format, so use 8. format in the put statement instead, and yymmdd8. on the input.


Data never sleeps
TurnTheBacon
Fluorite | Level 6

Worked like a charm, many thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 87350 views
  • 12 likes
  • 3 in conversation