BookmarkSubscribeRSS Feed
StudyBeane
Calcite | Level 5

Hi all, a little bit of info: I am very new to SAS and I am currently in grad school. I applied for a license from my school's IT department and they gave me SAS enterprise guide. For one of my assignments, I am using YRBSS 2021 data and I was given the formats catalog.

 

I was able to read it into what I believe is called the SAS windowing environment on a school computer. Now, I am trying to do it on my personal laptop for some more practice. Here is the code I was given to read in the dataset and format catalog, as well as a portion of the log. It seems to have worked but I don't think the formats were properly loaded. I know there's a lot of issues getting them in to SAS onDemand (which is what I usually use) so I was worried it might be the same issue here OR I am simply missing a line of code that would let me use them. Thanks for the help!

 

Code:

libname yrbs 'C:\Users\jld\Documents\Class\Lab';
libname library 'C:\Users\jld\Documents\Class\Lab';
 
data y21;
      set yrbs.yrbs2021;
run;
 
Log:

libname yrbs 'C:\Users\jld\Documents\Class\Lab';
NOTE: Libref YRBS was successfully assigned as follows:
Engine: V9
Physical Name: C:\Users\jld\Documents\Class\Lab 
29 libname library 'C:\Users\jld\Documents\Class\Lab';
NOTE: Libref LIBRARY refers to the same physical library as YRBS.
NOTE: Libref LIBRARY was successfully assigned as follows:
Engine: V9
Physical Name: C:\Users\jld\Documents\Class\Lab
30
31 data y21;
32 set yrbs.yrbs2021;
33 run;

NOTE: Format $H1S was not found or could not be loaded.
NOTE: Format $H2S was not found or could not be loaded.
NOTE: Format $H3S was not found or could not be loaded.
NOTE: Format $H4S was not found or could not be loaded.
NOTE: Format $H8S was not found or could not be loaded.
NOTE: Format $H9S was not found or could not be loaded.
NOTE: Format $H10S was not found or could not be loaded.
NOTE: Format $H11S was not found or could not be loaded.
NOTE: Format $H12S was not found or could not be loaded.
NOTE: Format $H13S was not found or could not be loaded.
NOTE: Format $H14S was not found or could not be loaded.
NOTE: Format $H15S was not found or could not be loaded.
NOTE: Format $H16S was not found or could not be loaded.
NOTE: Format $H17S was not found or could not be loaded.
NOTE: Format $H18S was not found or could not be loaded.
NOTE: Format $H19S was not found or could not be loaded.

2 REPLIES 2
Tom
Super User Tom
Super User

The code you shared is pointing the libref LIBRARY to the same directory as the libref YRBS.

(And from your LOG you are also doing that in the code you actually ran, but it is pointing to a slightly different directory name).

 

If you have not modified the setting of the FMTSEARCH system option then LIBRARY should be one of the librefs that is included in the search path.   So make sure to check the setting of FMTSEARCH option.

%put %sysfunc(getoption(fmtsearch));

That means it is going to look for a FORMAT CATALOG named LIBRARY.FORMATS.  So you should see a file named formats.sas7bcat in that directory.  If you do not have such a file then you do not have the format catalog.

 

But even if you do have such a file if it was made with a different version of SAS (different version number or different operating system or even different bit size used for the instruction sets) then it will be useless.  That is because unlike the SAS7BDAT format used for dataset the SAS7BCAT files are not cross environment compatible.

 

To really share the definition of the formats, like $H1S mentioned in your SAS log, it is safest to share a SAS program that can be run the create the format.  The next best is to use PROC CPORT to create a transport file that can be converted back into a format catalog by using PROC CIMPORT.  Another method to share is to convert the format catalog to a SAS dataset by using PROC FORMAT with the CNTLOUT= option.  You can then use PROC FORMAT on the new environment to with the CNTLIN= option to read in that dataset and make the format catalog.

ballardw
Super User

You likely need to add the library to the FMTSEARCH path.

By default SAS looks for formats in a very few locations. If you create formats in a different Library then you add them to  the search path with the OPTIONS statement.

 

Example:

options append=(fmtsearch=Yrbs);

would append the Formats catalog in the YRBS library to the current path. This would need to be done only once per session that wants to use the formats there. If for some reason the formats were stored in another catalog you would use the Libname.Catalog syntax to reference it.

You can check on the current value of your FMTSEARCH path using:

Proc options option=fmtsearch;
run;

The Log will show something like (I have more libraries in mine)

    SAS (r) Proprietary Software Release 9.4  TS1M7

 FMTSEARCH=(WORK USER SASHELP FP IPP PEDNSS   BRFSS)

Formats will be searched for in order. So if I attempt to use a format $somecustomfmt. SAS first looks in the WORK library , then the User, then FP .... until it is found or the list exhausted.

Knowing this order is important because you may want to test a format by placing it in the WORK library (proc format library=work ; value etc).  Which wouldn't replace the one in the YRBS library but would be used instead. Think debugging code or a temporary change that means you don't need to change the code in multiple places already using that format.

 

Very strong suggestion: Run Proc format to create a data set of the format definitions. Catalogs are very version dependent and may not work every where. If you have a data set you can use that recreate the formats on another system easier.

Proc format library=yrbs cntlout=yrbs.yrbs_fmtcntlout;
run;

will create data set named Yrbs_fmtcntlout in the Yrbs library of formats in that library.

Used with the Cntlin= option of Proc format it can recreate the formats.

I have some formats that started under SAS 8 that I have had to upgrade 4 times and this data set approached saved me a lot work. Though keeping the code is a very good idea but it sounds like you likely did not receive the source code file to create the formats.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 380 views
  • 1 like
  • 3 in conversation