1
votes

I am trying to load SAS data file together with its variable and value labels, but I cant seem to make it work.

I have 3 SAS files

  1. sas data ("data_final.sas7bdat")
  2. sas format dictionary that contains the format name, variable name/labels, etc ("formats.sas7bdat")

enter image description here

  1. sas format library that contains the format name, value name/labels,etc ("format_library.sas7bdat")

enter image description here

I am trying to load this to SPSS using the following code but it doesn't work. It loads the data and the variable labels but not the value labels.

GET SAS DATA='\data_final.sas7bdat'
     /FORMATS='\formats.sas7bdat'
     /FORMATS='\format_library.sas7bdat'.

Any help is greatly appreciated.

Thank you!

1
The SPSS command wants to reference a format catalog file, not a SAS dataset file. Do you have the actual format catalog (.sas7bcat extension) that PROC FORMAT would create from that FORMAT_LIBRARY dataset?Tom
yes I do have the catalog. its named as "formats.sas7bcat" which part of the code shall I update?dixi
I updated the file in the format to be '\formats.sas7bcat' instead of '\formats.sas7bdat' but it wont still load the value labels.dixi
The picture you posted of formats.sas7bdat is the variable level metadata (more like PROC CONTENTS output and is NOT PROC FORMAT output). The format_library dataset looks like PROC FORMAT output, so hopefully matches what is in the formats catalog. Do any of the values of the FORMAT variable in that dataset match the values of FMTNAME in the format_library dataset? That is how the connection is made, by attaching the format name to the variable name (NAME in your "formats" dataset).Tom
Do any of the values of the FORMAT variable in that dataset match the values of FMTNAME in the format_library dataset? <- yes it does. May I know how to connect the two formats in my get sas command?dixi

1 Answers

1
votes

The FORMATS= option wants the name of the SAS format catalog, not another SAS dataset. Catalogs use sas7bcat as the extension.

GET SAS DATA='\data_final.sas7bdat'
     /FORMATS='\formats.sas7bcat'.

If you really cannot get it to work then read in the formats_library.sas7bdat and look at the FMTNAME, TYPE, START, END and LABEL variables and use those to generate the SPSS code you need to attach data labels to your SPSS data.

FMTNAME is the name of the format. The TYPE determines if it is applies to character values or numeric values (or if in fact is an INFORMAT instead of FORMAT). The START and END mark the range of values (frequently they will be the same) and LABEL is the decoded value (aka the data label). Unlike in SPSS in SAS you only have to define the code/decode mapping once and then apply to as many variables as you want.

The dataset you show as being named formats.sas7bdat looks like it is the variable level metadata. That should list each variable (NAME) and what format, if any, has been attached to it (FORMAT). So if that shows there is a variable named FRED that has the format YESNO attached to it then look for records in format_library where FMTNAME='YESNO' and see what values it maps. So if FRED is numeric with values 1 and 2 then format YESNO might have one record with START='1' and LABEL='YES' and another with START='2' and LABEL='NO'.