Hi,
my sas-project has a lot of programms and I want to search all of these programms for specific variables. I want it to be automated. Means:
1. SAS shall use the column1 of the sas-dataset "variables". There are the variables it should search. Alternative: I would paste the list of variables into the syntax.
2. Search all programms (except the search-programm) of the current sas-session for the variables. For example: Is the variable1 from the "variables"-Dataset (reps. of the list within the syntax) part of any program of the running SAS session?
3. Pls write the result for every variable into the sas-dataset "result".
Is this doable? I need it, because the codeplan of my companies dataset changes every year. And I have to know, if "my variables" are part of this changes. Thank you for help!
A SAS session does not keep track of programs. It's just an engine which accepts code (in interactive mode even partial steps!) and executes it when told (e.g. RUN statement).
The concept of "program" exists in the editor only (when code is saved to a program file). Enterprise Guide has nodes within a project; if you consider the individual nodes as programs or the whole project as one program is up to you.
You could save all programs belonging to a project (not the "project" of EG, but a larger task you work on) into a single directory and then search for words in the files, like
data result;
variable = "&varname";
length fname fn $200;
infile "/path/*.sas" filename=fn;
input;
if findw(_infile_,variable)
then do;
fname = fn;
output;
end;
run;
To work through a list of variables, you could store their names in an array and loop the FINDW over that.
Ah okay, so, I tried it:
%let varname = DF0900P;
data result;
variable = "&varname";
length fname fn $200;
infile "[...]\syntax2021.sas" filename=fn;
input;
if findw(_infile_,variable)
then do;
fname = fn;
output;
end;
run;
The var-name DF0900P
is definitly part of the syntax "syntax2021.sas
". It looks like: [...] P_Kg=DF0900P; [...]
But it didnt find it. Any idea why?
The result of your code is:
Since you do not use blanks to separate your variable names from the rest of the code, you must initialize the delimiter list (third argument to FINDW) with the additional characters (like the operators); also use the "i" modifier (fourth argument) to prevent issues caused by mixed case.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.