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
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;
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.