Read Text File with DSL (from Fraktal SAS Programming): Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K |
K |
||
(10 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 5: | Zeile 5: | ||
|rechts=xx_right.png | |rechts=xx_right.png | ||
|übersicht=Data Step Programming (from Fraktal SAS Programming) | |übersicht=Data Step Programming (from Fraktal SAS Programming) | ||
− | |zurück= | + | |zurück=Create Dataset with DSL (from Fraktal SAS Programming) |
− | |vorwärts= | + | |vorwärts=Process Data using DSL (from Fraktal SAS Programming) |
}} | }} | ||
Zeile 20: | Zeile 20: | ||
St.Peter's#Business#2#333 | St.Peter's#Business#2#333 | ||
− | == Documented Code | + | |
+ | == Documented Code == | ||
{| class="wikitable" | {| class="wikitable" | ||
Zeile 28: | Zeile 29: | ||
|- | |- | ||
| | | | ||
− | + | ;filename source "&PATH.\&FILENAME."; | |
− | | '''Initiate data step processing with a DATA statement''' | + | |Generate a ''file reference'' with OS path and file name incl. extension. |
+ | |- | ||
+ | | | ||
+ | ;data hotels; | ||
+ | |Initiate data step processing with a DATA statement. | ||
+ | |- | ||
+ | | | ||
+ | :infile source dlm = '#'; | ||
+ | |Use ''fileref'' from above as source with the number sign '#' as field delimiter. | ||
|- | |- | ||
| | | | ||
− | + | :length hotel $16 category $16 no_of_beds rate_in_GBP 8; | |
− | | | + | |Allocate field space by supplying length in bytes and data type. |
|- | |- | ||
| | | | ||
− | + | :input hotel $ category $ no_of_beds rate_in_GBP; | |
− | | | + | |Specify data structure on text file. |
|- | |- | ||
| | | | ||
− | + | ;run <cancel>; | |
− | | '' | + | |End the data step run-group (use ''"cancel"'' for syntax check only). |
|- | |- | ||
| | | | ||
− | + | ;filename source clear; | |
− | | ''' | + | |Clear file reference thus un-locking the file referenced. |
+ | |} | ||
+ | |||
+ | |||
+ | == Results == | ||
+ | |||
+ | When issuing the phrase '''''"vt hotels"''''' in the command window of your '''''SAS''''' session, the following table might pop-up in a '''''"Viewtable Window"''''': | ||
+ | |||
+ | {| class="wikitable" | ||
+ | |- | ||
+ | ! hotel | ||
+ | ! category | ||
+ | ! no_of_beds | ||
+ | ! rate_in_GBP | ||
+ | |- | ||
+ | |Royal Inn||King's Suite||4||540 | ||
+ | |- | ||
+ | |The European||Standard||1||120 | ||
+ | |- | ||
+ | |St.Peter's||Business||2||333 | ||
|} | |} | ||
Zeile 53: | Zeile 81: | ||
|rechts=xx_right.png | |rechts=xx_right.png | ||
|übersicht=Data Step Programming (from Fraktal SAS Programming) | |übersicht=Data Step Programming (from Fraktal SAS Programming) | ||
− | |zurück= | + | |zurück=Create Dataset with DSL (from Fraktal SAS Programming) |
− | |vorwärts= | + | |vorwärts=Process Data using DSL (from Fraktal SAS Programming) |
}} | }} |
Aktuelle Version vom 4. August 2014, 16:34 Uhr
What is this?
SAS can read directly from any text file. Moreover SAS can read directly from any data source that has text file properties, such as FTP, HTTP, or XML, also from named pipes and DDE hotlinks.
When intending to read from a plain text file, you simply specify path and filename along with a description of the record structure. The text file shall look like this:
Royal Inn#King's Suite#4#540 The European#Standard#1#120 St.Peter's#Business#2#333
Documented Code
Code executed | Function performed |
---|---|
|
Generate a file reference with OS path and file name incl. extension. |
|
Initiate data step processing with a DATA statement. |
|
Use fileref from above as source with the number sign '#' as field delimiter. |
|
Allocate field space by supplying length in bytes and data type. |
|
Specify data structure on text file. |
|
End the data step run-group (use "cancel" for syntax check only). |
|
Clear file reference thus un-locking the file referenced. |
Results
When issuing the phrase "vt hotels" in the command window of your SAS session, the following table might pop-up in a "Viewtable Window":
hotel | category | no_of_beds | rate_in_GBP |
---|---|---|---|
Royal Inn | King's Suite | 4 | 540 |
The European | Standard | 1 | 120 |
St.Peter's | Business | 2 | 333 |