Hello All,
Warm greetings.
I appreared for a SAS developer interview recently ,and interviewer asked me this question .
Question:
There is a folder in windows directory system.
it has many SAS programs,which may or may not contain keyword 'Finance' .
Write a SAS program to find out all such SAS programs from the folder.
X command utility cannot be used for this.
Please advise .
Many thanks in advance for all the inputs.
Kind regards,
Neeraj Singh
You can use next code to serach for text files, including sas programs or logs, containing any desired given string:
%let search_string = rename;
%let suffix = sas;
%let root=/folders/myshortcuts/My_Folders/;
filename finp ("&root.sas_help/*.&suffix");
data results;
length fname _filepath $200;
infile finp filename = _filepath eov=_eov truncover;
input a_line $200.;
fname = _filepath;
if _eov=1 then do;
_n=0;
_eov=0;
end;
_n+1;
if find(a_line,"&search_string",'i')
then output;
keep _n a_line fname;
run;
If you are not using linux platform you may need adapt it to your OS.
What was your answer?
I did not give any answer. I was only able to think of X command utility and firing up a DOS command inside it.
but using SAS, i was speechles.. !! :'(
@thisisneeraj wrote:
I did not give any answer. I was only able to think of X command utility and firing up a DOS command inside it.
but using SAS, i was speechles.. !! :'(
FYI - That's part of the 'question' how do you respond to things you don't know the answer to, the interviewers want that information.
If you don't know the correct answer is, "I don't know but I would do X, Y, Z to find out". Or "My first option would be use an OS tool, but if I had to use SAS I would try reading the file in and searching manually, but the processing time would be much longer. I know this isn't an efficient method, but it would work".
Another option is using something like Windows Search. Unless the job was for an advanced programmer that's what I would be looking for at any rate.
Yes good point made by @Reeza here. Often questions are designed to see if you can do something, not necessarily how you do things. Quite often we see questions on here which start with something like "I have to use xyz". Knowing how to use a tool is one thing, knowing when to use a tool is another. I mean I could ask, "You are only allowed to use paint, please explain how you would write a report". Now you could fix on SAS and say well I would write a datastep which creates an array of pixels, thus drawing the commands to create the picture. Or you could say, why not use an application designed specifically create to create pictures, there are many out there varying costs, knowledge levels, lets do an assessment on how one of those could integrate into the currentflow best.
They do ask some tosh don't they. Anyways, you can do it with DOPEN and DREAD:
You can use next code to serach for text files, including sas programs or logs, containing any desired given string:
%let search_string = rename;
%let suffix = sas;
%let root=/folders/myshortcuts/My_Folders/;
filename finp ("&root.sas_help/*.&suffix");
data results;
length fname _filepath $200;
infile finp filename = _filepath eov=_eov truncover;
input a_line $200.;
fname = _filepath;
if _eov=1 then do;
_n=0;
_eov=0;
end;
_n+1;
if find(a_line,"&search_string",'i')
then output;
keep _n a_line fname;
run;
If you are not using linux platform you may need adapt it to your OS.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.