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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

4 REPLIES 4
Patrick
Opal | Level 21

@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?

Jinu302000
Fluorite | Level 6

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.

Patrick
Opal | Level 21

@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.

Reeza
Super User

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. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1144 views
  • 2 likes
  • 3 in conversation