BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robeldritch
Obsidian | Level 7

I'm wondering why when I run the following program (I'm running EG, 7.1), the table that opens up in the Output Data tab in EG shows the value labels ("Under 18", "18-24", or "25 and over") in the 'Age Range'n column, but when I open y.sas7bdat from the location in which I saved it, the table that is displayed just shows the value codes instead ("a", "b", or "c") for this column. 

 

proc format;
  VALUE  $agerangef 'a' = 'Under 18'
                    'b' = '18-24'
                    'c' = '25 and over';
run;

data lib.y;
	set x;
	length 'Age Range'n $ 11;
	if age<18 & age ~= . then 'Age Range'n = 'a';
		else if age >= 18 & age<=24 then 'Age Range'n = 'b';
		else if age >= 25 then 'Age Range'n = 'c'; 
	format 'Age Range'n $agerangef.;
run;

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you mean "value labels" in the SPSS sense, then you will be disappointed. SAS uses Formats, which are session based and the data set contains a reference to the default Format name. If the format is not available at the time you use the data set you may get an error (if option FMTERR is in effect) or the default format for the variable type will be used to create a display.

 

To use the format the SAS session that opens the file will need to know where the format definition is.Which means that either the Proc Format code has to be submitted in that session or have the format in a permanent library and use system option FMTSEARCH to tell SAS to look in that library for format information in addition to the SAS system formats.

And if you are using some other program to view the SAS data set I suspect you will be just plain out of luck.

View solution in original post

3 REPLIES 3
Reeza
Super User
EG has the nofmterr option set to NO, so it won't generate an error. When you double click and load the file from explorer, you're not attaching it to the format file so it shows you the raw values. If the nofmterr option was set differently it would generate an error about unfound formats.

When you open in within EG the formats are loaded and you'll see the formatted view. I wish there was a way to permanently attach formats to the data set 🙂
robeldritch
Obsidian | Level 7

Thanks to both of you--this was driving me crazy trying to figure out! 

ballardw
Super User

If you mean "value labels" in the SPSS sense, then you will be disappointed. SAS uses Formats, which are session based and the data set contains a reference to the default Format name. If the format is not available at the time you use the data set you may get an error (if option FMTERR is in effect) or the default format for the variable type will be used to create a display.

 

To use the format the SAS session that opens the file will need to know where the format definition is.Which means that either the Proc Format code has to be submitted in that session or have the format in a permanent library and use system option FMTSEARCH to tell SAS to look in that library for format information in addition to the SAS system formats.

And if you are using some other program to view the SAS data set I suspect you will be just plain out of luck.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 685 views
  • 2 likes
  • 3 in conversation