Read Text File with DSL (from Fraktal SAS Programming): Unterschied zwischen den Versionen

Aus phenixxenia.org
Zur Navigation springen Zur Suche springen
K
K
Zeile 9: Zeile 9:
 
}}
 
}}
  
 +
== 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, XML or named pipes and up to 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 Example ==
 +
 +
{| class="wikitable"
 +
|-
 +
! Code executed
 +
! Function performed
 +
|-
 +
|
 +
data plaintext;
 +
| '''Initiate data step processing with a DATA statement'''
 +
|-
 +
|
 +
infile source "&PATH.\&FILENAME." dlm = '#';
 +
| '''Specify text file's location and name and introduce the number sign '#' as delimiter'''
 +
|-
 +
|
 +
length hotel $16 category $16 no_of_beds rate_in_GBP 8;
 +
| '''Declare structure by supplying the field's length in bytes and data type'''
 +
|-
 +
|
 +
input hotel $ category $ no_of_beds rate_in_GBP;
 +
| '''Read the text file by specifying order and type'''
 +
|-
 +
|
 +
run;
 +
| '''Terminate the data step'''
 +
|}
  
 
{{SeitenNavigation1
 
{{SeitenNavigation1

Version vom 8. Juli 2014, 13:18 Uhr

Zurück

Übersicht

Vorwärts

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, XML or named pipes and up to 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 Example

Code executed Function performed
data plaintext;
Initiate data step processing with a DATA statement
infile source "&PATH.\&FILENAME." dlm = '#';
Specify text file's location and name and introduce the number sign '#' as delimiter
length hotel $16 category $16 no_of_beds rate_in_GBP 8;
Declare structure by supplying the field's length in bytes and data type
input hotel $ category $ no_of_beds rate_in_GBP;
Read the text file by specifying order and type
run;
Terminate the data step

Zurück

Übersicht

Vorwärts