BookmarkSubscribeRSS Feed
Konkordanz
Pyrite | Level 9

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!

3 REPLIES 3
Kurt_Bremser
Super User

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.

Konkordanz
Pyrite | Level 9

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:

Konkordanz_0-1689319445304.png

 

Kurt_Bremser
Super User

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 150 views
  • 0 likes
  • 2 in conversation