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

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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.

View solution in original post

7 REPLIES 7
thisisneeraj
Fluorite | Level 6

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.. !! :'( 

Reeza
Super User

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

Shmuel
Garnet | Level 18

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.

Peter_C
Rhodochrosite | Level 12
Could be simpler.
The required string was defined in mixed case so I expect it calls for a case sensitive search. The INPUT statement makes this really brief:
Data required_files( compress=yes) ;
Length filename filen $1000 ;
Retain filename ;
Infile "&folder/*.sas" filename= filen lrecl= 32000 ;
INPUT @'Finance' ;
If filename= filen then delete ; * found earlier ;
filename= filen ;
Run ;

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
  • 7 replies
  • 571 views
  • 1 like
  • 5 in conversation