find it using sas by david steves. would you like to be able to search sas programs for certain...

Post on 28-Mar-2015

214 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

“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 outputObs program directory list

12 okagent2.run /reference/code # as tt1 libname3 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;

Obs program directory list

12 okagent2.run /reference/code # as tt1 libname3 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"

Sample of output

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

top related