Exporting to a SAS XML File

If your dataset includes variables with more than 8 characters, you must use SAS XML instead of SAS Transport to export to SAS. The XML format is compatible with later versions of SAS (v8 and higher).

Export to SAS XML file

  1. Go to File|Export Interviews.
  2. Select SAS XML Files (.XML) from the Save as type drop-down box.
  3. Select Variable Subset if desired
  4. Click Options and make any desired changes.
  5. Click Save.

Export to SAS XML file dialog box

A dialog box will display the number of interviews exported to the selected location and the list of filenames exported.

Message: Number of interviews exported to the selected location and the list of filenames exported

SAS XML Export Function File Types

  • <filename>.XML: XML data file that contains response values and conforms to SAS XML engine generic markup.
  • <filename>_Map.XML: XML SXLEMAP file that contains data types and variable labels used by SAS XML import engine.
  • <filename>_Fmt.XML: XML file that contains value labels for creating user-defined formats.
  • <filename>.SAS: SAS program file that contains a SAS Format statement which associates variables with format names.

SAS XML Save As Options

After clicking the Options button from the Save As box, the SAS XML Options box will open. The following label, Special Value, and missing data options may be set on the SAS Options window.

SAS XML Save As Options box

  • Include Question Number with Variable Label: Check this box to include the question number with the variable label. The question number will be added at the beginning of the label. (default setting is not checked)
  • Special Value Recodes: To change how QDS Special Values are exported, select an option from the Special Value Recodes, Recode to box.
    • Special Codes: Convert to Special Codes, as defined in the Design Studio. Special Responses include Don't Know (default = 9 … 7), Refused (default = 9 … 8), Not Applicable (default = 9 … 9), and Skipped (default = 9 … 9). (default setting)
    • Missing (.): Convert to SAS System Missing.
    • Range Bottom: Convert to the minimum allowable value for the corresponding variable, as defined in the Design Studio.
    • Range Top: Convert to the maximum allowable value for the corresponding variable, as defined in the Design Studio.
    • Range Middle: Convert to the midpoint of the allowable range for the corresponding variable, as defined in the Design Studio.
    • Specified Values: Convert to the values specified in the boxes to the right. The default specified values for SAS will be enabled when the Specified Values radio button is selected. These suggested values in the boxes may be modified. See Changing Special Code Values.
  • Data Set Name: Specify a name for data set in SAS. For example, if you enter “Baseline_Responses”, then this is referenced as “<libname>.Baseline_Responses” when running commands in SAS. The maximum length allowed is 32 characters; the first character must be a letter or an underscore character, and subsequent characters can be letters, digits, and underscores. The default data set name is set to “Interview”.

After you have finished updating and reviewing your options, click OK.

Click the Save button to (re-)create your files for export. Data, variable names, and labels will be included for all Standard Version interviews.

Changing Special Code Values

To change how QDS special values are exported, select the Specified Values option from the Special Value Recodes box. Default values are listed in the boxes to the right; however, they can be changed to any other SAS special missing value.

Specified Values option on Special Value Recodes box

Export Limits

SAS XML files format imposes the following maximum lengths:

  • Variable names: 32 characters
  • Variable labels: 256 characters (Chinese, Japanese, and Korean: 128 characters)
  • Value labels: Unlimited
  • Text responses: 32,767 characters.

Read SAS XML Files into SAS

The following SAS commands show an example of how to import the XML files into v8 or higher of the SAS software. Note that you can change the default name of the dataset ("Interview") in the Data Set Name field under SAS XML Save As Options

/*SAS commands using SAS XML Libname Engine to create a data set */

/* from the exported data and map files */

filename qdsm 'C:\Users\User\Documents\Survey\HealthSurvey_Map.xml';

filename qdsd 'C:\Users\User\Documents\Survey\Health Survey.xml';

 

libname qdsd xmlv2 xmlmap=qdsm;/* “xmlmap” name needs to match name of map file (e.g., qdsm)*/

run;

libname qdsout v9'c:\Users\User\Documents\Survey\';

proc copy in=qdsd out=qdsout;/*“in” name needs to match name of data file (e.g., qdsd)*/

run;

Create SAS format catalog and apply to SAS dataset

/* To create a Format Library, import the myfile_Fmt file*/

libname labs xmlv2 'C:\Users\User\Documents\Survey\Health Survey_Fmt.XML';

 

/* Save "labs" dataset as a SAS format catalog and apply it to qdsd.interview */

libname library 'c:\Users\User\Documents\Survey';

proc format library=library cntlin=labs.vlabels;

run;

 

/* Assign formats to data file */

data final;

set qdsout.interview; /*note: the default name of the dataset is"interview"*/

FORMAT

<contents of SAS file>;
run;