DATA Step, Macro, Functions and more

reading raw data and if it satisfies the condition move it to different folder

Reply
Occasional Contributor
Posts: 9

reading raw data and if it satisfies the condition move it to different folder

Hi,

I have 2k text files present in 2k different folders.i want to check for the data in text file where the variable name

should be in (name,nm,firname,first_nm,first_name). and all these variable i.e name,nm,firname,first_nm,first_name

has a data in it which may be 009871,0987522,x065432,000984631 like this..and if i find this variables present i want to copy the folder containg that text file to different folder..

please help me out how these can be done

Super User
Posts: 10,770

Re: reading raw data and if it satisfies the condition move it to different folder

Firstly, use OS command to list all these file path

dir c:\temp\*.txt  /s /b

 

After that use the following code to check data.

 

data want;

 input x $80.;

infile dummy filevar=x filename=fname end=last;

do while(not last);

  input .................

 ..........

end;

cards;

c:\temp\a.txt

c:\temp\b.txt

;

run;

Super User
Posts: 23,695

Re: reading raw data and if it satisfies the condition move it to different folder

1. Write some code to process and check one file/move it if required. 

Not exactly sure here, the details are a bit vague. You could be searching for a specific pattern in the first row (column names) or you could be looking for a value. Either way, using some Operating System search commands are probably the fastest approach.

Here's an example of searching a single text file for a word, but not a pattern: 

https://gist.github.com/statgeek/26cf789d6da0ce941e447022fdccf0f4

 

2. Get a list of all files

http://support.sas.com/kb/45/805.html

 

3. Convert Step 1 to a macro

https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/

 

4. Use CALL EXECUTE or DOSUBL to call macro.

https://gist.github.com/statgeek/beb97b1c6d4517dde3b2

 

 

 

This should let get you started. Feel free to post back you need further help, include your code, log and an explanation of what's not working. 

 


@nid197 wrote:

Hi,

I have 2k text files present in 2k different folders.i want to check for the data in text file where the variable name

should be in (name,nm,firname,first_nm,first_name). and all these variable i.e name,nm,firname,first_nm,first_name

has a data in it which may be 009871,0987522,x065432,000984631 like this..and if i find this variables present i want to copy the folder containg that text file to different folder..

please help me out how these can be done



 

 

Regular Contributor
Posts: 209

Re: reading raw data and if it satisfies the condition move it to different folder

The whole task looks like something to be solved by os-scripts, but could you please explain again what you want to find in the files? Are you looking for a special header-line and the data is of no importance to decide whether the file has to be copied?
Ask a Question
Discussion stats
  • 3 replies
  • 101 views
  • 0 likes
  • 4 in conversation