importcode

Converts coded terminology stored in SAS dataset to SAS format or SAS format into dataset.

%importcode(data =dataset with coded values,
                           
fmtname =format catalog,
                           
codedvar =variable with coded values,
                            decodedvar =
variable with decoded values,
                            convert =convert data or format,
                            dictname=
destination dictionary name,
                            codename =
codelist name in dictionary);
 

Where

Is Type...

And represents...

dataC (200 char)Dataset containing the coded and decoded values.  
fmtnameC (200 char)The name of the format.  For example: RACEFMT is used as a name for coded race categories.
codedvarC (200 char Optional)A variable name that is to be created or read as input which contains the coded values.  For example, if the codes are:

F = Female
M = Male

The coded variable is the column that contains F and M.  If not specified, it will default to the variable CODEDVAR.
decodedvarC (200 char Optional)A variable name that is to be created or read as input which contains the de-coded values.  For example, if the codes are:

F = Female
M = Male

The coded variable is the column that contains Female and Male.  If this is not specified, it will default to the variable: DECODEDVAR.
convertC (200 char Optional)The direction of conversion.  This can be converting SAS datasets with coded values to WORK.FORMAT catalog or converting a format catalog to a dataset.  Valid values include:
  • Data (default)
  • Format
dictnameC (200 char)Dictionary name in which the coded values will be imported.  
codenameC (200 char)The code list name inside the specified name.  If the name already exist, it will overwrite.  Otherwise, it will create a new codelist. 

Details
This tool will convert SAS formats from coded values stored in a dataset.  It can also create a SAS dataset with the coded values from a SAS catalog.  The default conversion will be from a SAS dataset to formats created in the work area as WORK.FORMATS.  In will actually generate the PROC FORMAT code and submit it so that the formats are available.   

  • The format catalog that is to be created or read as input is expected to be in the WORK area.  The location is WORK.FORMATS.
  • If the data set has many values, the macro will get all the distinct values between the coded and decoded column to generate the format.

Example    

%importcode(indata=mylib.mydata,
                      fmtname=genderfmt);

%importcode(indata=mylib.mydata,
                       fmtname=genderfmt,
                       codedvar=myvar1,
                       codedvar=myvar2);

%importcode(indata=mylib.mydata,
                       fmtname=genderfmt,
                       codedvar=myvar1,
                       codedvar=myvar2,
                       convert=format);

     ThesQA - Manage Controll Terminology, Meta-Xceed Inc.© 2009
Bookmark and Share