80 likes | 199 Vues
Discover how to effectively search SAS programs for specific expressions using the “Find.It” technique by David Steves. This guide provides a step-by-step approach to locate terms like "libname" within your SAS code, helping you understand the context of your libname statements. Learn to adapt this script to search for any expressions in your SAS programs or other code types, and make informed decisions based on the scan results. Enhance your coding efficiency with this reliable method.
E N D
“Find It” Using SAS By David Steves
Would you like to be able to search SAS programs for certain expressions? • Example: I have a list of SAS programs which I want to search for the literal “libname”, because I want to see what libname statements are in the code.
libname unix1 '/home/unix1';sample of unix1.list_programs; Obs code map_directory 1 okagent.run /reference/code 2 okagent.sas /reference/code 3 okagent2.run /reference/code 4 okagent2.sas /reference/code 5 actinv.run /outbound_extracts/code
Sample of output Obs program directory list 1 2 okagent2.run /reference/code # as tt1 libname 3 okagent2.run /reference/code libname tt1 '/prodtemp'; 4 okagent2.run /reference/code /* change on 11/27 to spds4 libname */ 5 okagent2.run /reference/code libname gsdata sasspds "gsdata" host= "ga016dxx" 6 okagent2.run /reference/code libname ext sasspds “ext" host= "ga016dxx"
data _null_; set unix1.list_programs end=no_more; call symput('mapto'||left(_n_),map_directory); call symput('program'||left(_n_),code); if no_more then call symput('pgcnt',_n_); run; %put &pgcnt.; ** Creation of SAS DATASET –no observations yet*; data all_prod; format program $35. directory $35. list $80.; run;
%macro progloop; %local i; %do i=1 %to &pgcnt; %macro search(dir,ftoconv); data tt1; infile "/source/&dir/&ftoconv." lrecl=32767 end=_eof; input; INPUT statement with no arguments. _infile_ automatic variable find_it1 = find(_infile_,'libname','I'); *I ignores Character case*; format program $35. directory $35. list $80.; program="&ftoconv."; directory="&dir."; if find_it1 > 0 then list= _infile_; if find_it1 > 0; run; proc append base=all_prod data=tt1(keep=directory program list) force; run; %mend search; %search(&&mapto&i,&&program&i); %end; %mend progloop; %progloop;
Sample of output • Obs program directory list • 1 • 2 okagent2.run /reference/code # as tt1 libname • 3 okagent2.run /reference/code libname tt1 '/prodtemp'; • 4 okagent2.run /reference/code /* change on 11/27 to spds4 libname */ • okagent2.run /reference/code libname gsdata sasspds "gsdata" host= "ga016dxx" • okagent2.run /reference/code libname ext sasspds “ext" host= "ga016dxx"
Interesting points • Take this code and check for other expressions • Use this SAS code to scan other non-SAS programs • Ability to make decisions with scan results • More Info about the find function go to http://support.sas.com/onlinedoc/913/getDoc/en/lrdict.hlp/a002267763.htm