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

I have some code which works to extract the Last Modified date from an excel file:

 

 

data last_mod_date;

  rc = filename("onefile","F:\test.xlsx");

  fid=fopen("onefile"); /*fid is the file-id*/

  Mod_Date=finfo(fid,'Last Modified');

  rc = fclose(fid);

  rc = filename("onefile");

run;

 

 

The data is stored as at 200 character length as the following 

 

January 14, 2020 12:25:02

 

Now I want to take the above and convert it to the following string

 

YYYYMMDD_HHMM

 

I've tried several difference methods to try and extract the month/day/year/hours/minutes individually but none of them seem to work. Any ideas? 

 

Note; I need this to work for any string date I extract (dates will be after January 1, 2020 if that helps) 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

data test;
dt='January 14, 2020 12:25:02';/*string*/
num_dt=input(dt,anydtdtm35.);/*numeric datetime value*/
/*Extract date value, time value and concatenate to a new string value*/
want_date=cats(put(datepart(num_dt),yymmddn8.),'_',compress(put(timepart(num_dt),hhmm.),':'));
drop num_dt;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

data test;
dt='January 14, 2020 12:25:02';/*string*/
num_dt=input(dt,anydtdtm35.);/*numeric datetime value*/
/*Extract date value, time value and concatenate to a new string value*/
want_date=cats(put(datepart(num_dt),yymmddn8.),'_',compress(put(timepart(num_dt),hhmm.),':'));
drop num_dt;
run;
NickK
Fluorite | Level 6
Thanks. Works perfectly.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 651 views
  • 1 like
  • 2 in conversation