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

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen
K
K
 
(17 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
[[Kategorie:Zazy]]
 
[[Kategorie:Zazy]]
 
{{SeitenNavigation1
 
{{SeitenNavigation1
|hoch=Duck_zazy_com.png
+
|hoch=call a macro bubble 0.png
 
|links=xx_left.png
 
|links=xx_left.png
 
|rechts=xx_right.png
 
|rechts=xx_right.png
 
|übersicht=Macro Programming (from Fraktal SAS Programming)
 
|übersicht=Macro Programming (from Fraktal SAS Programming)
|zurück=Macro XDIR (from Fraktal SAS Programming)
+
|zurück=Macro XSET (from Fraktal SAS Programming)
|vorwärts=Macro XDIR (from Fraktal SAS Programming)
+
|vorwärts=Macro XEDIT (from Fraktal SAS Programming)
 
}}
 
}}
  
%MACRO xdir(xpath);
+
== What it does ==
filename path pipe "dir /b &XPATH." lrecl = 256;
+
 
data _NULL_;
+
'''This SAS Macro reads entries from a specified OS directory and writes results to the SAS LOG screen.'''
infile path;
+
* When no directory is specified, a pop-up window is defined and opened to ask the user for the directory name.
input entries $ 1-256;
+
 
  put entries;
+
== Annotated Code ==
run;
+
 
%MEND xdir;
+
{| class="wikitable"
 +
! Code executed
 +
! Function performed
 +
|-
 +
|
 +
<font face="Courier New">
 +
;%MACRO xdir(xpath);
 +
</font>
 +
|Start macro definition with name and positional parameter ''xpath''.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;%IF %LENGTH(&XPATH.) = 0 %THEN %DO;
 +
</font>
 +
|Define branch when parameter ''xpath'' is not supplied.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;%WINDOW path
 +
</font>
 +
|Start definition of pop-up window.
 +
|-
 +
|
 +
<font face="Courier New">
 +
: irow = 20 rows = 14 icolumn = 30 columns = 64       
 +
</font>
 +
|Specify position and size of window.
 +
|-
 +
|
 +
<font face="Courier New">
 +
: #4 @5 'Enter path: ' xpath 40 attr = underline               
 +
</font>
 +
|Specify constant text shown, parameter name to be populated and attributes.
 +
|-
 +
|
 +
<font face="Courier New">
 +
''';'''
 +
</font>
 +
|Terminate pop-up window definition statement.
 +
|-
 +
|
 +
<font face="Courier New">
 +
:%DISPLAY path;
 +
</font>
 +
|Open pop-up window.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;%END;
 +
</font>
 +
|Finalize branch definition for empty parameter ''xpath''.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;filename path pipe "dir /b ""&XPATH.""" lrecl = 256;
 +
</font>
 +
|Define text data stream with type '''''pipe''''' and logical record length.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;data _NULL_;
 +
</font>
 +
|Initiate data step run group.
 +
|-
 +
|
 +
<font face="Courier New">
 +
:length entry $256;
 +
</font>
 +
|Specify length in byte for character field ''entry''.
 +
|-
 +
|
 +
<font face="Courier New">
 +
:infile path length = lrecl;
 +
</font>
 +
|Open text data stream ''path''.
 +
|-
 +
|
 +
<font face="Courier New">
 +
:input entry $varying256. lrecl;
 +
</font>
 +
|Specify structure of data stream ''path''.
 +
|-
 +
|
 +
<font face="Courier New">
 +
:  put entry;  
 +
</font>
 +
|Write value from field ''entry'' to the SAS LOG screen.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;run;
 +
</font>
 +
|Terminate data step run group.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;filename path clear;
 +
</font>
 +
|Revoke definition of text data stream.
 +
|-
 +
|
 +
<font face="Courier New">
 +
;%MEND xdir;
 +
</font>
 +
|END macro definition with name
 +
|}
 +
 
 +
== How it is done ==
 +
 
 +
# Upon initialization the presence of the parameter ''"xpath"'' is checked.
 +
## If not present, a pop-up window is defined and popped-up to ask the user for the path.
 +
# The path is then used to create a text data file reference of type '''''pipe'''''.
 +
# The created fileref is then read with an appropriate input statement.
 +
## No dataset is created by using '''dummy dataset name ''_NULL_'''''.
 +
## Each text line input is directly output to the log screen as expected.
 +
 
 +
== Special Effects ==
 +
 
 +
Generally, '''''SAS''''' is expecting fixed record length data when reading from a text data source. As is the case in our example here, this condition is not met. When reading varying record length data, '''''SAS''''' needs information about the particular record length. This is obtained by using the '''''"length ="''''' option in the infile statement. The variable named after the "=" - sign will hold the length of each line ready for use by the '''''"varying"''''' format in the input statement.
 +
 
 +
== More Special Effects ==
 +
 
 +
If you prefer working with interactive tools instead of rough batch runs, then try a [[Macro rXDIR (from Fraktal SAS Programming)|slightly modified version]] of this macro.
  
 
{{SeitenNavigation1
 
{{SeitenNavigation1
|hoch=Duck_zazy_com.png
+
|hoch=call a macro bubble 0.png
 
|links=xx_left.png
 
|links=xx_left.png
 
|rechts=xx_right.png
 
|rechts=xx_right.png
 
|übersicht=Macro Programming (from Fraktal SAS Programming)
 
|übersicht=Macro Programming (from Fraktal SAS Programming)
|zurück=Macro XDIR (from Fraktal SAS Programming)
+
|zurück=Macro XSET (from Fraktal SAS Programming)
|vorwärts=Macro XDIR (from Fraktal SAS Programming)
+
|vorwärts=Macro XEDIT (from Fraktal SAS Programming)
 
}}
 
}}

Aktuelle Version vom 6. Januar 2016, 18:39 Uhr

Zurück

Übersicht

Vorwärts

What it does

This SAS Macro reads entries from a specified OS directory and writes results to the SAS LOG screen.

  • When no directory is specified, a pop-up window is defined and opened to ask the user for the directory name.

Annotated Code

Code executed Function performed

%MACRO xdir(xpath);

Start macro definition with name and positional parameter xpath.

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

Define branch when parameter xpath is not supplied.

%WINDOW path

Start definition of pop-up window.

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

Specify position and size of window.

#4 @5 'Enter path: ' xpath 40 attr = underline

Specify constant text shown, parameter name to be populated and attributes.

;

Terminate pop-up window definition statement.

%DISPLAY path;

Open pop-up window.

%END;

Finalize branch definition for empty parameter xpath.

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

Define text data stream with type pipe and logical record length.

data _NULL_;

Initiate data step run group.

length entry $256;

Specify length in byte for character field entry.

infile path length = lrecl;

Open text data stream path.

input entry $varying256. lrecl;

Specify structure of data stream path.

put entry;

Write value from field entry to the SAS LOG screen.

run;

Terminate data step run group.

filename path clear;

Revoke definition of text data stream.

%MEND xdir;

END macro definition with name

How it is done

  1. Upon initialization the presence of the parameter "xpath" is checked.
    1. If not present, a pop-up window is defined and popped-up to ask the user for the path.
  2. The path is then used to create a text data file reference of type pipe.
  3. The created fileref is then read with an appropriate input statement.
    1. No dataset is created by using dummy dataset name _NULL_.
    2. Each text line input is directly output to the log screen as expected.

Special Effects

Generally, SAS is expecting fixed record length data when reading from a text data source. As is the case in our example here, this condition is not met. When reading varying record length data, SAS needs information about the particular record length. This is obtained by using the "length =" option in the infile statement. The variable named after the "=" - sign will hold the length of each line ready for use by the "varying" format in the input statement.

More Special Effects

If you prefer working with interactive tools instead of rough batch runs, then try a slightly modified version of this macro.

Zurück

Übersicht

Vorwärts