- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Dear SAS experts
I have in my dataset a value label (value label: a term I know from working with Stata for many years) created using proc format; value specification. It is intended for a variable which contains thousands of data points and therefore the value label includes specification of MANY values. However, I would very much like to add just one more value label (a label for .).
Is it possible to simply modify the existing value label such that it includes one more value label, while maintaining the existing value labels?
I am working in a system where I can simply upload the format and thereby apply the value label directly, i.e. I don't actually have to specify the value label using proc format; value.. This saves me MANY lines of code. I can upload the full code into my program file and thereby simply add the additional value label (i.e. add an additional line of code), but I would much rather simply modify the existing format and - if possible - save many lines of code.
Thank you
Best regards
Martin
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you want display missing values as? If it is just a single letter try just changing the MISSING system option.
Why not define a new format that references the old format and overrides the decode used for missing values.
proc format ;
value newfmt
. = 'New decode'
other = [oldfmt.]
;
run;
And then use the new format with your variable(s).
proc freq data=have;
format varname newfmt.;
tables varname;
run;
Otherwise please explain more clearly what you are doing.
If you have SAS code that defined the format changing the way it displays missing values should be a simple one line change to the code.
If you have a SAS dataset you are using with CNTLIN= option of PROC FORMAT to define the format then a simple one line change to the dataset is all you will need. Make sure you understand how to use the HLO variable in the control dataset.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To modify a format to add a condition when the original data is missing, you have to change the VALUE statement in PROC FORMAT that created the format. Then you have to run this changed PROC FORMAT.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The programming to do this is not simple, but is relatively short.
If you are using a permanently saved format, you need to now the name of both the format itself (easy) and the format catalog holding the format (not as easy). Then it would take three steps:
- Download the contents of the format into a SAS data set. This means using PROC FORMAT with the CNTLOUT= option.
- Modify that downloaded SAS data set (see code below).
- Re-generate the format using the modified SAS data set. This means using PROC FORMAT with the CNTLIN= option.
Sample code to modify the SAS data set that was downloaded from the format:
data modified_version;
set downloaded_format end=done;
output;
if done;
start = /* new value being defined in the format */;
end = /* same new value being defined in the format */;
label = /* label you want to assign to that new value */;
output;
run;
Take a look and see if this seems like a viable approach for you. THere are definitely a few complex details, but perhaps only a dozen lines of programming.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can always use %include to copy the code of an existing SAS program into your current code.
So you can keep the definition of a format in a separate file and use this wherever you need it.
If you really want to add another "line" to an existing format checkout the code sample below. This will overwrite the existing format.
/*
* original format
*/
proc format;
value myfmt
11 = "eleven"
12 = "twelve"
13 = "thirteen"
;
run;
/*
* use it
*/
proc print data=sashelp.class;
format age myfmt.;
run;
/*
* write out definition
*/
proc format cntlout=fmtdef;
select myfmt;
run;
/*
* insert additional "line"
*/
proc sql;
insert into fmtdef
set
fmtname = "myfmt"
, type = "n"
, start = "14"
, end = "14"
, label = "fourteen"
;
quit;
/*
* recreate it
*/
proc format cntlin=fmtdef;
run;
/*
* check it out
*/
proc print data=sashelp.class;
format age myfmt.;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you want display missing values as? If it is just a single letter try just changing the MISSING system option.
Why not define a new format that references the old format and overrides the decode used for missing values.
proc format ;
value newfmt
. = 'New decode'
other = [oldfmt.]
;
run;
And then use the new format with your variable(s).
proc freq data=have;
format varname newfmt.;
tables varname;
run;
Otherwise please explain more clearly what you are doing.
If you have SAS code that defined the format changing the way it displays missing values should be a simple one line change to the code.
If you have a SAS dataset you are using with CNTLIN= option of PROC FORMAT to define the format then a simple one line change to the dataset is all you will need. Make sure you understand how to use the HLO variable in the control dataset.