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

Hi, I've asked similar question few days back but this time round, the situation is a lil bit different.

I have 4 variables of date time combination that i want to merge them into a datetime column. Variables as below

Day is numeric

Month is Character(January February....)

Year is numeric

Time is CHARACTER

 

Take note that my original data contains   before i split them into 4 individual variable (day month year time). Hence you will see i use scan and then input.

 

now the issue is, i tried converting the character time by using :

INPUT(chartime,time.)

 

but it will give me the time in 10000 or 73000 or 56800 value instead of 10:00 and etc

 

so here are my code

proc format;
invalue inmonth
  'January' = 1
  'February' = 2
  'March' = 3
  'April' = 4
  'May' = 5
  'June' = 6
  'July' = 7
  'August' = 8
  'September' = 9
  'October' = 10
  'November' = 11
  'December' = 12
;

data converttonewdatetime;
    length 	demand_occurence_day 8 demand_occurence_month $10 demand_occurence_year 8 demand_occurence_time 
		demand_occurence_newdate 8 newdemand_occurence_date 8;


demand_occurence_day=scan(demand_occurence,1,' ');
	   demand_occurence_month=scan(demand_occurence,2,' ');
	   demand_occurence_year=scan(demand_occurence,3,' ');
	   demand_occurence_time=input(scan(demand_occurence,-1,' '),time.);
		demand_occurence_newdate=mdy(input(demand_occurence_month,inmonth.),demand_occurence_day,demand_occurence_year);
		newdemand_occurence_date = dhms(demand_occurence_newdate,0,0,demand_occurence_time);

run;

 

What did i do wrong?

The result set is as below.

wrong datetime.PNG

1 ACCEPTED SOLUTION
3 REPLIES 3
Patrick
Opal | Level 21

Have you checked your log?

Your informat inmonth. doesn't match your data (only 3 letter months in data). I would assume this results in a missing date and some SAS warning or at least a note about missing data generated.

WorkingMan
Calcite | Level 5
You mean the function mdy? I cannot see 3 words data Patrick. Can you help me further ?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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