How to find a file’s creation date
Posted: 10 April 2012 03:11 PM   [ Ignore ]
Newbie
Rank
Total Posts:  4
Joined  2011-10-20

Hi,

I’ve been working on linking identifiers across various WRDS datasets and came across a cute piece of code that finds the creation date of a file. It’s helpful because some of these linking files (e.g., IBES.IDSUM) will have a begin date (exdate) and an end date (valdate) for the link between identifiers but if the link is valid as of the date the file was created then the valdate is missing. So, then when you want to join to the table using the ranges you have to accomodate for missing values in your join.

This code finds the creation date of a file and puts it into a macro variable (create_dt) that can be used to update the missing valdates.

I’ve uploaded a file containing the code within a macro.

Here is an example of how to call the macro. The first line is needed because without it the macro creates the variable locally. But the %let stmt makes it global.

%let create_dt=;
%CREATEDATE (DSPATH=e:\wrds\CRSP\stocknames.sas7bdat);

If you just want to use it in open code, just start with a %let DSPATH=...; statement then continue with the “filename…” statement.

File Attachments
CreateDate.sas  (File Size: 3KB - Downloads: 414)
Profile
 
 
Posted: 10 April 2012 03:32 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

Hi Dreppen,

Thanks! Looks very useful!

I noticed the forum scrips have difficulty with (some) SAS code (it thinks the ampersand is the beginning of an HTML code, which ends with a semicolon).
To be sure, would you mind editing your post and upload a text file with the code?

thanks,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 30 April 2012 12:40 PM   [ Ignore ]   [ # 2 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi Dreppen,

When running the macro, I get an error “There is not enough space on the disk” (even when testing it with a small dataset). Any idea what is happening?

5691 %CreateDate(DSPATH=C:\wrds_libs\matching\sasdata\ibes_idsum.sas7bdat);
MPRINT(CREATEDATE):  options nonotes;
SYMBOLGEN:  Macro variable DSPATH resolves to C:\wrds_libs\matching\sasdata\ibes_idsum.sas7bdat
MPRINT(CREATEDATE):  filename foo pipe “dir C:\wrds_libs\matching\sasdata\ibes_idsum.sas7bdat
/t:c /a:-d “;
MPRINT(CREATEDATE):  data _null_;
MPRINT(CREATEDATE):  infile foo firstobs=6;
MPRINT(CREATEDATE):  input cr_date ?? :mmddyy8. cr_time ?? & time8.;
MPRINT(CREATEDATE):  if cr_date eq . then stop;
MPRINT(CREATEDATE):  create_date=putn(cr_date,‘best10.’);
MPRINT(CREATEDATE):  create_time=putn(cr_time, ‘time8.’);
MPRINT(CREATEDATE):  call symputx(“create_dt”, create_date);
MPRINT(CREATEDATE):  call symputx(“create_time”, create_time);
MPRINT(CREATEDATE):  run;
Stderr output:
There is not enough space on the disk.
MPRINT(CREATEDATE):  options notes;
WARNING: Apparent symbolic reference CREATE_DT not resolved.
WARNING: Apparent symbolic reference CREATE_TIME not resolved.
&create;_dt &create;_time

thanks,

Joost

 

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile
 
 
Posted: 30 April 2012 01:18 PM   [ Ignore ]   [ # 3 ]
Newbie
Rank
Total Posts:  4
Joined  2011-10-20

I am not sure. I ran it on the same dataset (IDSUM) and got the output below. The only thing that looks different is the quotation marks but that may be the website formatting.

%createdate(dspath=e:\wrds\ibes\idsum.sas7bdat);

MLOGIC(CREATEDATE):  Beginning execution.
MLOGIC(CREATEDATE):  This macro was compiled from the autocall file C:\MyFiles\Coding\SAS\Macros\createdate.sas
MLOGIC(CREATEDATE):  Parameter DSPATH has value e:\wrds\ibes\idsum.sas7bdat
MPRINT(CREATEDATE):  options nonotes;
SYMBOLGEN:  Macro variable DSPATH resolves to e:\wrds\ibes\idsum.sas7bdat
MPRINT(CREATEDATE):  filename foo pipe “dir e:\wrds\ibes\idsum.sas7bdat /t:c /a:-d “;
MPRINT(CREATEDATE):  data _null_;
MPRINT(CREATEDATE):  infile foo firstobs=6;
MPRINT(CREATEDATE):  input cr_date ?? :mmddyy8. cr_time ?? & time8.;
MPRINT(CREATEDATE):  if cr_date eq . then stop;
MPRINT(CREATEDATE):  create_date=putn(cr_date,‘best10.’);
MPRINT(CREATEDATE):  create_time=putn(cr_time, ‘time8.’);
MPRINT(CREATEDATE):  call symputx(“create_dt”, create_date);
MPRINT(CREATEDATE):  call symputx(“create_time”, create_time);
MPRINT(CREATEDATE):  run;
INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation may result.
    2:152   create_date
    2:191   create_time
MPRINT(CREATEDATE):  options notes;
MLOGIC(CREATEDATE):  %PUT &create;_dt &create;_time
SYMBOLGEN:  Macro variable CREATE_DT resolves to 19047
SYMBOLGEN:  Macro variable CREATE_TIME resolves to 14:35:00
19047 14:35:00
MLOGIC(CREATEDATE):  Ending execution.

Profile
 
 
Posted: 30 April 2012 01:45 PM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  901
Joined  2011-09-19

hi Dreppen,

Thanks for looking into it; looks we have some mystery on our hands… smile

best regards,

Joost

 Signature 

To reply/post new questions: Please use the group WRDS/SAS on Google Groups! http://groups.google.com/d/forum/wrdssas

Profile