DATA Step, Macro, Functions and more

Num8 to YYMMDDN8

Reply
Contributor
Posts: 41

Num8 to YYMMDDN8

Hi I have a date like 20180101 which is Numeric 8 and I need to transform it to YYMMDDN8.

 

I am doing it just with a proc sql but it's not working well...

 

like this

SELECT
t1.DN_PEO FORMAT=YYMMDDN8.;

The date is after written like this:

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

and still in num 8.

 

Do you know where is the problem here?

PROC Star
Posts: 8,117

Re: Num8 to YYMMDDN8

Sounds like you are trying to do something like the following:

data have;
  input DN_PEO;
  cards;
20180101
;

proc sql;
  create table want as
    select input(put(DN_PEO,8.),yymmdd8.) as DN_PEO format=YYMMDDN8.
      from have
  ;
quit;

Art, CEO, AnalystFinder.com

 

 

Super Contributor
Posts: 478

Re: Num8 to YYMMDDN8

Date values in SAS are stored as number of days from 1st Jan 1960. In your example your saying SAS that 20180101 days form 1st Jan 1960. Which is why you are getting *****. First thing is you need to tell SAS how to read data otherwise it will follow its nature.Smiley Wink

 

I suggest use @art297 solution. Converting the numeric values into character and then telling SAS to convert back into numeric date values.

Also you need to understand about FORMAT(How to show data) and INFORMAT (How to read data).

Thanks,
Suryakiran
Contributor
Posts: 45

Re: Num8 to YYMMDDN8

[ Edited ]

Hi,

 

I have the same problem here!

I used this:

input(put(t1.DAT,8.),YYYYMMDD8.)

And the solution doesn't work for me.

 

I modified the format to YYMMDDN8., so the format is well going from numeric8. to date8. but I also have 

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

for every date.

 

 

Do you know why?

 

Some of values of DAT at the top rows of the table are null. Can it explain?

Thanks

PROC Star
Posts: 8,117

Re: Num8 to YYMMDDN8

You'd have to provide an example of your data. My guess is that your dates are already either date or datetime values and you simply need to add the desired format.

 

I suggest that you create a new thread and ask your question there.

 

Art, CEO, AnalystFinder.com

 

Ask a Question
Discussion stats
  • 4 replies
  • 132 views
  • 0 likes
  • 4 in conversation