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

Hello 

I'm working on a data which has numeric variable in the following way.

 

20061213
20061213
20061213
20061214

 

I tried converting it in to date format by using following code.

 

data TEST;

set recnou.rec19sep17;

format dtmep date8. ;

where CDFPRO='P';

keep nocont cnp dtmep unpaid;

run;

 

I'm getting following output.

 

********
********
********
********
********
********
********
********
********

 

can any one please tell me the reason for the above output and how do I rectify the problem.

i want the date to be mm/dd/yyyy

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

You can't format it as a date because for that to work, the number has to be a legitimate SAS date value, in other words, it must be the number of days since Jan 1, 1960. Try this UNTESTED CODE

 

newvar=input(put(dtmep,$8.),yymmdd8.);
format newvar date8.;
--
Paige Miller

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20
If you have readable dates as numeric without a format, you need to transform the values.
First use put () to a text string, ind use input() to do the conversion using a specific informat that matches your current date format.
Data never sleeps
Unstefan
Calcite | Level 5

i solve it  right this

data TEST;

set recnou.rec19sep17;

DATE2 = INPUT(PUT(Dtmep,8.),yyMMDD8.);

FORMAT DATE2 MMDDYY10.;

where CDFPRO='P';

keep nocont cnp date2 unpaid;

run;

PaigeMiller
Diamond | Level 26

You can't format it as a date because for that to work, the number has to be a legitimate SAS date value, in other words, it must be the number of days since Jan 1, 1960. Try this UNTESTED CODE

 

newvar=input(put(dtmep,$8.),yymmdd8.);
format newvar date8.;
--
Paige Miller

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 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
  • 3 replies
  • 796 views
  • 0 likes
  • 3 in conversation