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

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen
K
K
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 24: Zeile 24:
 
</font>  
 
</font>  
 
|
 
|
 +
Start macro definition with name and positional parameter ''xpath''
 
|-
 
|-
 
|
 
|
Zeile 30: Zeile 31:
 
</font>  
 
</font>  
 
|
 
|
 +
Declare macrovariable ''rpath'' as global
 
|-
 
|-
 
|
 
|
Zeile 36: Zeile 38:
 
</font>  
 
</font>  
 
|
 
|
 +
Empty macrovariable ''xpath''
 
|-
 
|-
 
|
 
|
Zeile 42: Zeile 45:
 
</font>  
 
</font>  
 
|
 
|
 +
Start definition for macro window ''path''
 
|-
 
|-
 
|
 
|
Zeile 48: Zeile 52:
 
</font>  
 
</font>  
 
|
 
|
 +
Set coordinates for macro window ''path''
 
|-
 
|-
 
|
 
|
Zeile 54: Zeile 59:
 
</font>  
 
</font>  
 
|
 
|
 +
Define 1st output line containing value from macrovariable ''rpath''
 
|-
 
|-
 
|
 
|
Zeile 60: Zeile 66:
 
</font>  
 
</font>  
 
|
 
|
 +
Define 2nd output line and field attributes to read macrovariable ''xpath''
 
|-
 
|-
 
|
 
|
Zeile 66: Zeile 73:
 
</font>  
 
</font>  
 
|
 
|
 +
End definition of macro window ''path''
 
|-
 
|-
 
|
 
|
Zeile 72: Zeile 80:
 
</font>  
 
</font>  
 
|
 
|
 +
Invoke macro window ''path''
 
|-
 
|-
 
|
 
|
Zeile 78: Zeile 87:
 
</font>  
 
</font>  
 
|
 
|
 +
Branch to label ''leave'' for condition "''null value entered''"
 
|-
 
|-
 
|
 
|
Zeile 84: Zeile 94:
 
</font>  
 
</font>  
 
|
 
|
 +
Append value from macrovariable ''xpath'' to macrovariable ''rpath''
 
|-
 
|-
 
|
 
|
Zeile 90: Zeile 101:
 
</font>  
 
</font>  
 
|
 
|
 +
Create file reference of type ''pipe'' to read entries from directory named in ''rpath''
 
|-
 
|-
 
|
 
|
Zeile 96: Zeile 108:
 
</font>  
 
</font>  
 
|
 
|
 +
Output roughly formatted header containing value from ''rpath''
 
|-
 
|-
 
|
 
|
Zeile 102: Zeile 115:
 
</font>  
 
</font>  
 
|
 
|
 +
Initiate datastep w/o creating a dataset
 
|-
 
|-
 
|
 
|
Zeile 108: Zeile 122:
 
</font>  
 
</font>  
 
|
 
|
 +
Specify field length to read directory entries' names into
 
|-
 
|-
 
|
 
|
Zeile 114: Zeile 129:
 
</font>  
 
</font>  
 
|
 
|
 +
Open data stream from file reference
 
|-
 
|-
 
|
 
|
Zeile 120: Zeile 136:
 
</font>  
 
</font>  
 
|
 
|
 +
Define tokens coming in of varying length with name ''entry''
 
|-
 
|-
 
|
 
|
Zeile 126: Zeile 143:
 
</font>  
 
</font>  
 
|
 
|
 +
Instantly write ''entry'' to the LOG screen
 
|-
 
|-
 
|
 
|
Zeile 132: Zeile 150:
 
</font>  
 
</font>  
 
|
 
|
 +
Terminate the data step
 
|-
 
|-
 
|
 
|
Zeile 138: Zeile 157:
 
</font>  
 
</font>  
 
|
 
|
 +
Close data stream ''path''
 
|-
 
|-
 
|
 
|
Zeile 144: Zeile 164:
 
</font>  
 
</font>  
 
|
 
|
 +
Recursively call macro ''rxdir'' with parameter ''rpath''
 
|-
 
|-
 
|
 
|
Zeile 150: Zeile 171:
 
</font>  
 
</font>  
 
|
 
|
 +
Define GOTO label 'leave'
 
|-
 
|-
 
|
 
|
Zeile 156: Zeile 178:
 
</font>  
 
</font>  
 
|
 
|
 +
Empty macrovariable ''rpath''
 
|-
 
|-
 
|
 
|

Aktuelle Version vom 24. November 2014, 19:05 Uhr

Zurück

Übersicht

Vorwärts

What it does

This SAS Macro provides the function from XDIR in an interactive mode.

  • The recursive use of macro invocation keeps the macro "alive" until no further user input is made.
  • It might be of some interest to the novice user, how easy it is, to turn a simple "home-grew" function into an interactive tool.
Code executed Function performed

%MACRO rxdir(xpath);

Start macro definition with name and positional parameter xpath

%GLOBAL rpath;

Declare macrovariable rpath as global

%LET xpath = ;

Empty macrovariable xpath

%WINDOW path

Start definition for macro window path

irow = 20 rows = 14 icolumn = 130 columns = 64

Set coordinates for macro window path

#3 @5 "Current Path: &RPATH."

Define 1st output line containing value from macrovariable rpath

#5 @5 'Enter path: ' xpath 40 attr = blink

Define 2nd output line and field attributes to read macrovariable xpath

;

End definition of macro window path

%DISPLAY path;

Invoke macro window path

%IF %LENGTH(&XPATH.) = 0 %THEN %GOTO leave;

Branch to label leave for condition "null value entered"

%LET rpath = &RPATH.&XPATH.\;

Append value from macrovariable xpath to macrovariable rpath

filename path pipe "dir /b ""&RPATH.""" lrecl = 256;

Create file reference of type pipe to read entries from directory named in rpath

%PUT ---&RPATH.---;

Output roughly formatted header containing value from rpath

data _NULL_;

Initiate datastep w/o creating a dataset

length entry $256;

Specify field length to read directory entries' names into

infile path length = lrecl;

Open data stream from file reference

input entry $varying256. lrecl;

Define tokens coming in of varying length with name entry

put entry;

Instantly write entry to the LOG screen

run;

Terminate the data step

filename path clear;

Close data stream path

%RXDIR(&RPATH.)

Recursively call macro rxdir with parameter rpath

%LEAVE:

Define GOTO label 'leave'

%LET rpath = ;

Empty macrovariable rpath

%MEND rxdir;

END macro definition with name

Zurück

Übersicht

Vorwärts