Reading and Writing Data


Open a Client Data Set

To create a DataObject from a SAS data set on the client, you can use the CreateFromFile method of the DataObject class. Type or copy the following statements into a program window, and select ProgramRun from the main menu.

 
   declare DataObject dobj; 
   dobj = DataObject.CreateFromFile("Hurricanes"); 
   DataTable.Create( dobj ); 

The first statement declares dobj to be an IMLPlus variable that refers to a DataObject. The second statement creates the DataObject and populates it with data from the specified data set. (More information about methods in the DataObject class is available in the SAS/IML Studio online Help.)

If you omit the file extension from the argument of CreateFromFile (as in this example), an extension of sas7bdat is assumed.

The last statement creates a DataTable, which displays the data in tabular form. The data table might appear behind your program window, so move the program window if necessary. While it is reassuring to see the data table and to know that your data set was correctly opened, this last statement is not necessary: the DataObject is created even if you do not create a DataTable.

Note: You can specify an absolute Windows pathname for the argument passed to the CreateFromFile method. However, if you specify a partial pathname as in the preceding example, then SAS/IML Studio searches for the file relative to certain directories. The Hurricanes data set is distributed with SAS/IML Studio. The directory that contains sample data sets (C:\Program Files\SAS\SASIMLStudio\12.1\Data Sets) is, by default, one of the directories automatically searched. See the SAS/IML Studio online Help for information about how to add or change directory search paths.