If you don't want to write the code yourself, you have to hire someone or search for code that you can adept to your needs.
Please provide:
- A proper title
- A proper explanation
- An example of what you have (what is "the sas files used in a sas code " ?)
- An example of what you want (what is "the list which has sas file n domain as a naming" ? )
Spending a few seconds to haphazardly throw together incomplete words in the hope that they make sensible sentences, and then expecting volunteers to spend time guessing your needs and providing a thoughtful and comprehensive reply is unrealistic to say the least.
Hi @Stephenjohn
Welcome to the SAS Communities! Guess people haven't realized that you're new to this forum else your welcome would have been a bit warmer.
Help us help you and try to formulate the problem as clear as you can also providing the necessary detail.
A lot of people here are also more than happy to share actual and tested code. You just need to provide representative sample data for this (as a SAS data step creating such data and not as a screenshot please!) and eventually the code you've already tried. Even if such code isn't properly working it's still often very helpful to get to better understand where you are coming from.
Please find the example below of the requirement i am looking for.
ex: this is a sas code where i am taking data from a lib raw which has have and bright.. I want to check whether HAVE and BRIGHT are used in the particular code(want.sas file). I have a list to compare in the form of an excel.. Can we have a macro to find this ..
So, you want to analyse your sas-code files.
What exactly do you expect as result?
How do you identify the datasets you want to find?
i have to find a text from the sas codes and compare it with the excel file
eg: below is a sas file named AE.sas and i want to find 'raw.ae' from this code.
proc sql;
create table ae_supp as
select a.*,b.* from raw.ae
as a inner join suppae_act as b on a.usubjid=b.usubjid1 and a.aeseq=b.idvarval;
quit;
to identify the which text needs to be searched in the sas file we have a excel file as below.
eg
text sas file
raw.ae AE.sas
raw.cm CM.sas
raw.ae ho.sas
etc.
Thanks, this is clearer. I wouldn't think about a macro yet, I would start with thinking about how you would check one .sas file to see if it has a string in it.
So, I think the first step could be to write a program that would search the file AE.sas, to see if it has the string "raw.ae" in it.
Have you tried writing that program? This could be done with a SAS data step (reading AE.sas as a data file). Or could be done with other languages. I'd suggest you try writing a DATA step to read that file and parse it. You could also try searching lexjansen.com for papers about SAS log scanners. The log scanners typically read in a .log file and search for specific words. Both a .log file and a .sas file are just text files. So the approach used by a log scanner to search for a string should also work for scanning a .sas file.
Once you have a working approach for scanning one file, you can move on to automating it with a macro, or CALL EXECUTE, or similar.
I tried with the below program.. but this can give only 1 search at a time...
I had to write the macro Search n number of times to get an output in different datasets..and then append and then compare with the excel file.. if there is a way to find multiple strings from multiple sas files stored in one path that would help.
%macro search(results,dataset,input);
%let root= path;
filename finp ("&root./&input..sas");
data &results.;
length fname _filepath frname $200;
infile finp filename = _filepath eov=_eov truncover;
input a_line $200.;
fname =compress(scan(_filepath,-1,'\'),".sas");
if _eov=1 then do;
_n=0;
_eov=0;
end;
_n+1;
frname=compress(scan(a_line,-1,'.'),';');
if find(a_line,"&dataset.",'i')
then output;
keep _n fname frname;
run;
%mend search;
Does that macro you wrote work for searching one file for one string?
I would think it would be possible to write a DATA step that would read in a list of files, and search each of them for a string. But the hassle would be that you would need to manage the lookup of which string should be looked for in each file.
If that macro works for one file, I would look into using CALL EXECUTE. You could read in the Excel file which has one row for each file to search, and lists the file name and the string to search for. And CALL EXECUTE would call your macro once for each row, passing in the as parameters the values in the columns "raw file" and "sas code." You would get one output file from each search, but you could use PROC APPEND (probably inside the macro), so that each time you call the macro it does the search, and adds a record with the results of that search.
Easy:
If the team members who coded the SAS programs religiously used "valid two-level SAS names". Then writing SAS code to open all SAS code files and do string searches will work. This is still difficult, but this is the best case scenario.
Bruno_SAS wrote useful code here to bring multiple text files into a dataset.
Solved: Re: Read all text files into one dataset - SAS Support Communities
Hard:
They did not use valid two-level SAS names: I would begin with familiarizing myself PROC SCAPROC.
It's a lot easier to help you when you provide all the information.
This does what you want.
data TEXT;
input TEXT $ FILENAME $;
cards;
raw.ae AE.sas
raw.cm CM.sas
raw.ae ho.sas
run;
data CHECK;
set TEXT;
infile IN filevar=FILENAME end=EOF;
do until (EOF);
input;
if find(_INFILE_, TEXT, 't') then output;
end;
run;
Please adapt to your needs and report. The path is most likely missing.
How will i assign a path in this code to check for the file names.
> How will i assign a path in this code to check for the file names.
Add it in the FILENAME variable.
Thank you. that was helpful.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.