Macro XAMINE (from Fraktal SAS Programming): Unterschied zwischen den Versionen

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen
K
K
Zeile 47: Zeile 47:
 
;data entries;
 
;data entries;
 
</font>  
 
</font>  
|Initiate datastep to access OS directory content
+
|Initiate data step to access OS directory content
 
|-
 
|-
 
|
 
|
Zeile 77: Zeile 77:
 
;run;
 
;run;
 
</font>  
 
</font>  
|Terminate datastep
+
|Terminate data step
 
|-
 
|-
 
|
 
|
Zeile 83: Zeile 83:
 
;data dirs;
 
;data dirs;
 
</font>  
 
</font>  
|Initiate datastep to access OS directories listing
+
|Initiate data step to access OS directories listing
 
|-
 
|-
 
|
 
|
Zeile 107: Zeile 107:
 
;run;
 
;run;
 
</font>  
 
</font>  
|Terminate datastep
+
|Terminate data step
 
|-
 
|-
 
|
 
|
Zeile 113: Zeile 113:
 
;%DO ie = 1 %TO &NE.;
 
;%DO ie = 1 %TO &NE.;
 
</font>  
 
</font>  
|
+
|Start macro loop to process entries one by one with loop index 'ie'
 
|-
 
|-
 
|
 
|
Zeile 119: Zeile 119:
 
;data _NULL_;
 
;data _NULL_;
 
</font>  
 
</font>  
|
+
|Initiate data step without creating a dataset
 
|-
 
|-
 
|
 
|
Zeile 125: Zeile 125:
 
:set entries(firstobs = &IE. obs = &IE.);
 
:set entries(firstobs = &IE. obs = &IE.);
 
</font>  
 
</font>  
|
+
|Read row number 'ie' from dataset 'entries'
 
|-
 
|-
 
|
 
|
Zeile 131: Zeile 131:
 
:call symput('entry',compress(translate(entry,'_','(-)')));
 
:call symput('entry',compress(translate(entry,'_','(-)')));
 
</font>  
 
</font>  
|
+
|Write value from read row to macro variable 'entry' with intermediate name processing
 
|-
 
|-
 
|
 
|
Zeile 137: Zeile 137:
 
:call symput('xentry',trim(left(entry)));
 
:call symput('xentry',trim(left(entry)));
 
</font>  
 
</font>  
|
+
|Write value from read row to macro variable 'xentry'
 
|-
 
|-
 
|
 
|
Zeile 143: Zeile 143:
 
;run;
 
;run;
 
</font>  
 
</font>  
|
+
|Terminate data step
 
|-
 
|-
 
|
 
|
Zeile 149: Zeile 149:
 
:%PUT |;
 
:%PUT |;
 
</font>  
 
</font>  
|
+
|Write string '|' to the LOG
 
|-
 
|-
 
|
 
|
Zeile 155: Zeile 155:
 
:%PUT &XPATH.&XENTRY.;
 
:%PUT &XPATH.&XENTRY.;
 
</font>  
 
</font>  
|
+
|Write full path and filename to the LOG
 
|-
 
|-
 
|
 
|
Zeile 161: Zeile 161:
 
:%LET dir =;
 
:%LET dir =;
 
</font>  
 
</font>  
|
+
|Reset value for macro variable 'dir'
 
|-
 
|-
 
|
 
|
Zeile 167: Zeile 167:
 
;data _NULL_;
 
;data _NULL_;
 
</font>  
 
</font>  
|
+
|Initiate data step without creating a dataset
 
|-
 
|-
 
|
 
|
Zeile 173: Zeile 173:
 
: set dirs(where = (dir = "&XENTRY.")) end = EOF;
 
: set dirs(where = (dir = "&XENTRY.")) end = EOF;
 
</font>  
 
</font>  
|
+
|Read value from dataset 'dirs' for
 
|-
 
|-
 
|
 
|

Version vom 29. Januar 2015, 19:26 Uhr

Zurück

Übersicht

Vorwärts

Code executed Function performed

%MACRO xamine(xpath,etype);

Start Macro definition with name and positional parameters xpath and etype

%GLOBAL ne ie dir;

Declare global macro variables for communication with called macros

%LOCAL xpath xentry entry etype;

Declare local macro variables

filename entries pipe "dir /b &XPATH." lrecl = 256;

Open access path to listing of OS directory content of type 'file'

filename dirs pipe "dir /b /ad &XPATH." lrecl = 256;

Open access path to listing of OS directory content of type 'dir'

data entries;

Initiate data step to access OS directory content

length entry $256;

Declare length of data field 'entry'

infile entries length = lrecl end = EOF;

Set pointer to access path 'entries'

input entry $varying256. lrecl;

Read from 'entries' with variable field length

if EOF then call symput('ne',trim(left(put(_N_,8.))));

Write count of entries to macro variable 'ne'

run;

Terminate data step

data dirs;

Initiate data step to access OS directories listing

length dir $256;

Declare length of data field 'dir'

infile dirs length = lrecl end = EOF;

Set pointer to access path 'dirs'

input dir $varying256. lrecl;

Read from 'dirs' with variable field length

run;

Terminate data step

%DO ie = 1 %TO &NE.;

Start macro loop to process entries one by one with loop index 'ie'

data _NULL_;

Initiate data step without creating a dataset

set entries(firstobs = &IE. obs = &IE.);

Read row number 'ie' from dataset 'entries'

call symput('entry',compress(translate(entry,'_','(-)')));

Write value from read row to macro variable 'entry' with intermediate name processing

call symput('xentry',trim(left(entry)));

Write value from read row to macro variable 'xentry'

run;

Terminate data step

%PUT |;

' to the LOG

%PUT &XPATH.&XENTRY.;

Write full path and filename to the LOG

%LET dir =;

Reset value for macro variable 'dir'

data _NULL_;

Initiate data step without creating a dataset

set dirs(where = (dir = "&XENTRY.")) end = EOF;

Read value from dataset 'dirs' for

if EOF then call symput('dir',trim(left(put(_N_,8.))));

run;

%IF &DIR. = 1 %THEN %DO;

%PUT +----;

%XDIR(&XPATH.&XENTRY.);

%PUT +----;

%END;

%ELSE %DO;

%IF %LENGTH(&ETYPE.) ne 0 %THEN %DO;

%IF %INDEX(%SCAN(&ETYPE.,2,_),%SCAN(&XENTRY,2,.)) != 0 %THEN %DO;

%GLOBAL windir;

%XSET(windir);

%PUT +----;

%PUT | File &XENTRY. opened in external editor WordPad.;

SYSTASK command "&WINDIR.\write.exe ""&XPATH.\&XENTRY.""";

%PUT +----;

%END;

%IF %INDEX(%SCAN(&ETYPE.,1,_),%SCAN(&XENTRY,2,.)) != 0 %THEN %DO;

%PUT +----;

%PUT | File &XENTRY. opened in SAS program editor window.;

%XEDIT(&XENTRY.,&XPATH.);

%PUT +----;

%END;

%END;

%END;

%END;

proc sql;

drop table dirs;

drop table entries;

quit;

filename entries clear;

filename dirs clear;

%MEND xamine;

End Macro definition with name

Zurück

Übersicht

Vorwärts