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

Hello, the date format in the code below create blanks for the columns DAY, MO, YR, and DATE.

The rest of the results are fine except for the new date breakouts.


DATA SALES (keep= CUSTCODE MO DAY YR DATE HOUR_1-HOUR_24 KWH_TOT);
SET MONTHLY_SALES ;
IF OPCOCODE = "DPL";


DAY = DAY(LOAD_DATE) ;
MO= MONTH(LOAD_DATE);
YR= YEAR(LOAD_DATE) ;
DATE = MDY(MO,DAY,YR) ;

FORMAT DATE DATE7.;

KWH_SUB = (SUM(OF HOUR_1-HOUR_24)* 1000);
KWH_TOT = sum(KWH_SUB,(HOUR_2_*1000));
IF HOUR_2_>0 THEN HOUR_2 =MEAN(HOUR_2,HOUR_2_);
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Then you have a datetime variable, not a date variable. 

You need to convert it to a date to use the MONTH/DAY/YEAR functions.

 

Use the DATEPART() function to convert them to dates first.

View solution in original post

5 REPLIES 5
Reeza
Super User

What does the log say?

And what's the type/format of the date variable?

tobyfarms
Fluorite | Level 6

@Reeza

Here is a portion of the log pertaining to the date.


NOTE: Invalid argument to function DAY(1737763200) at line 29 column 9.
NOTE: Invalid argument to function MONTH(1737763200) at line 30 column 7.
NOTE: Invalid argument to function YEAR(1737763200) at line 31 column 7.
OPCOCODE=DPL LOAD_DATE=25JAN2015:00:00:00

 

The properties indicate being in datetime20. format.

Thanks.

Reeza
Super User

Then you have a datetime variable, not a date variable. 

You need to convert it to a date to use the MONTH/DAY/YEAR functions.

 

Use the DATEPART() function to convert them to dates first.

tobyfarms
Fluorite | Level 6

That fixed it.  Issue resolved!

Thanks @Reeza

ballardw
Super User

And instead of pulling things apart to use this:

DATE = MDY(MO,DAY,YR) ;

 

Date = datepart(Load_date);

 

Unless you have a very specific reason later to have  month, day and year variables.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2523 views
  • 1 like
  • 3 in conversation