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 ?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1122 views
  • 0 likes
  • 3 in conversation