Compare modified date between SAS dataset and CSV files

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Compare modified date between SAS dataset and CSV files

Would like to compare the modified date between SAS dataset and csv file and ensure both are correct. Output when there is any difference.

 

SAS datasets are there in one folder. CSV files are there in another folder for a study---One parent study folder and two sub folders for sas datasets and CSv files. Likewise many parent folders are there (200+).

 

Ideally csv files are the converted files for the respective dataset. We would like to know the modified date by comparing each and output if there is any difference in date.

 

Could you please help me on this. Thanks very much for your support inadvance.


Accepted Solutions
Solution
‎10-17-2017 02:02 AM
Respected Advisor
Posts: 4,695

Re: Compare modified date between SAS dataset and CSV files

[ Edited ]
Posted in reply to Jinu302000

@Jinu302000

What are these modified date? Is this a date column in your data or are you talking about the file modification date? If it's the file modification date then how could that ever be the same for the .csv source and the target SAS data set?

View solution in original post


All Replies
Solution
‎10-17-2017 02:02 AM
Respected Advisor
Posts: 4,695

Re: Compare modified date between SAS dataset and CSV files

[ Edited ]
Posted in reply to Jinu302000

@Jinu302000

What are these modified date? Is this a date column in your data or are you talking about the file modification date? If it's the file modification date then how could that ever be the same for the .csv source and the target SAS data set?

New Contributor
Posts: 2

Re: Compare modified date between SAS dataset and CSV files

Thanks Patrick for your prompt response. 

 

Yes, it is file modification date.

Note:- We are not looking any data in the files columns. We are considering only file modification date present in the folder level.

 

When we execute the program for a requirement, we will get output as sas dataset in one folder and csv file in another folder. The file modified date should be on the same date (we are not considering the time).

 

Let's say when we execute a program called Test (SAS system program), then we will get output as Test_JJ.sas in one folder and Test_JJ.csv in another folder as mentioned below. 

 

Clean case:- File modified date should match with sas dataset and csv file for respective file.

 

location for sas dataset:- \Customers\Projects\YYY\162111\SAS_dataset

 

Example:-

File                  date modified

Test_JJ.sas     10/10/2017 1:15AM

 

location for csv files:- \Customers\Projects\YYY\162111\SAS_text

 

File                  date modified

Test_JJ.csv     10/10/2017  1:17AM

 

While executing the program, both files will generate on the same date with different time period.

 

Dirty case:- If there is any difference in file 'date modified' between SAS dataset and CSV file, then it should output. 

 

Example:-

location for sas dataset:- \Customers\Projects\YYY\162111\SAS_dataset

 

File                  date modified

Test_RR.sas     14/10/2017 1:15AM

 

location for csv files:- \Customers\Projects\YYY\162111\SAS_text

 

File                  date modified

Test_RR.csv     15/10/2017  1:17AM

 

Here date modified is mismatching (14/10/2017 for Test_RR.sas vs 15/10/2017 for Test_RR.csv) for the respective csv and sas file and hence this should output.

 

I would appreciate if you could help me on this. Thanks very much Patrick for your time on this.

Respected Advisor
Posts: 4,695

Re: Compare modified date between SAS dataset and CSV files

[ Edited ]
Posted in reply to Jinu302000

@Jinu302000

I guess you will have to create a directory listing and then read the data into a SAS tables. Then compare the records in the tables (i.e. join over filename without extension and compare the dates).

I'm using Windows so below sample code for Windows using the DIR command. You can do something similar with the UNIX LS command.

%let rootPath=c:\temp;
data textFiles SASTables;
  
  infile  "dir /tw &rootPath\*.txt" pipe end=last truncover dlm=' ';
  do until(last);
    input dt ?? :ddmmyy10. _d1:$1. _d1:$1. _d1:$1. name $100.;
    format dt date9.;
    if not missing(dt) then output textFiles;
  end;

  last=0;
  infile  "dir /tw &rootPath\*.sas7bdat" pipe end=last truncover dlm=' ';
  do until(last);
    input dt ?? :ddmmyy10. _d1:$1. _d1:$1. _d1:$1. name $100.;
    format dt date9.;
    if not missing(dt) then output SASTables;
  end;

  drop _:;
run;

Capture.JPG

 

N.B: You will need option XCMD set for this to work. If NOXCMD is set and you can't change it then either run the code in batch where you can pass in options (-XCMD) or Google a bit to find the code which allows you to list a directory with SAS even if you're not allowed to directly issue OS commands.

Super User
Posts: 23,343

Re: Compare modified date between SAS dataset and CSV files

Posted in reply to Jinu302000

You can use the FINFO function. 

 

http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#n0vegoaf5t6s31n1wu...

 

If you need to get the paths see the SAS 9.4 macro appendix fir an example. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 219 views
  • 2 likes
  • 3 in conversation