DATA Step, Macro, Functions and more

Date format issue - date9 not working

Accepted Solution Solved
Reply
Contributor
Posts: 53
Accepted Solution

Date format issue - date9 not working

Hello,

I am importing several tables where the date field is in Character format(1994/06/17), which I want to place is date9 format (17JUN1994).  I know the fix is simple but I am missing something in my code. .

 

1 %_eg_hidenotesandsource;

5 %_eg_hidenotesandsource;

28

29

30 Data work.Weather_Merge;

31 set ACY_F_100117_2017_10_02_07_30_21 DCA_F_100117_2017_10_02_07_30_27 ILG_F_100217_2017_10_03_07_30_37

31 ! SBY_F_100217_2017_10_03_07_30_42;

32 where 'O/F'n = 'O';

33

34 rename 'O/F'n = Status;

35 hour=substr('Forecast Date'n,11,3);

36 date=substr('Forecast Date'n,1,10);

37

38 format date date9.;

______

484

NOTE 484-185: Format $DATE was not found or could not be loaded.

39

40 Drop 'Forecast Date'n 'Forecast Date_0001'n;

41 Run;

NOTE: There were 98 observations read from the data set WORK.ACY_F_100117_2017_10_02_07_30_21.

WHERE 'O/F'n='O';

NOTE: There were 98 observations read from the data set WORK.DCA_F_100117_2017_10_02_07_30_27.

WHERE 'O/F'n='O';

NOTE: There were 98 observations read from the data set WORK.ILG_F_100217_2017_10_03_07_30_37.

WHERE 'O/F'n='O';

NOTE: There were 98 observations read from the data set WORK.SBY_F_100217_2017_10_03_07_30_42.

WHERE 'O/F'n='O';

NOTE: The data set WORK.WEATHER_MERGE has 392 observations and 15 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.01 seconds

 

Data work.Weather_Merge;
set ACY_F_100117_2017_10_02_07_30_21 DCA_F_100117_2017_10_02_07_30_27 ILG_F_100217_2017_10_03_07_30_37 SBY_F_100217_2017_10_03_07_30_42;
where 'O/F'n = 'O';

rename 'O/F'n = Status;
hour=substr('Forecast Date'n,11,3);
date=substr('Forecast Date'n,1,10);

format date date9.;

Drop 'Forecast Date'n 'Forecast Date_0001'n;
Run;

 


Accepted Solutions
Solution
‎11-13-2017 11:48 AM
Super User
Posts: 6,543

Re: Date format issue - date9 not working

Posted in reply to tobyfarms

You are creating DATE as a character variable.  But to apply the DATE9 format, DATE must be numeric, with a value that matches SAS's idea of what a date looks like.  Fortunately, all of this can be corrected by changing this statement:

 

date=substr('Forecast Date'n,1,10);

 

Instead, it should be:

 

date=input('Forecast Date'n, yymmdd10.) ;

View solution in original post


All Replies
Solution
‎11-13-2017 11:48 AM
Super User
Posts: 6,543

Re: Date format issue - date9 not working

Posted in reply to tobyfarms

You are creating DATE as a character variable.  But to apply the DATE9 format, DATE must be numeric, with a value that matches SAS's idea of what a date looks like.  Fortunately, all of this can be corrected by changing this statement:

 

date=substr('Forecast Date'n,1,10);

 

Instead, it should be:

 

date=input('Forecast Date'n, yymmdd10.) ;

Contributor
Posts: 53

Re: Date format issue - date9 not working

Posted in reply to Astounding
That Worked. Thanks for the quick fix.
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 193 views
  • 0 likes
  • 2 in conversation