I have a user-defined format (created by cntlin= from a SAS dataset); I want to add values to the format and turn it into a multilabel format.
I am unsure how to do this ... .
SAS Help Center: Results: PROC FORMAT
@dwaldo wrote:
So, HLO=SM is what tells SAS this is a multi-label format? Not the most obvious solution I have ever encountered, but it does the trick -- thanks!
By the way -- where is this (and the other fields in that cntlout file) documented? Even The Google was perplexed
I think this is a really good discussion if really good.
Multiple Facts about Multilabel Formats
In this blog you find an example that creates a multilabel format using the CNTLIN= option in PROC FORMAT.
Creating and Using Multilabel Formats
https://blogs.sas.com/content/sgf/2016/12/16/creating-and-using-multilabel-formats/
Also ... in this NESUG 2008 conference paper, you find MULTILABEL FORMATS WITH CNTLIN DATASETS.
Multiple Facts about Multilabel Formats
Gwen D. Babcock, New York State Department of Health, Troy, NY
https://lexjansen.com/nesug/nesug08/cc/cc14.pdf
Or ... go here:
creating multi labels using proc format cntlin
Instead of using a CNTLIN= dataset, you can also generate your PROC FORMAT code dynamically from a dataset. This is called data-driven dynamic code generation. You use a datastep with a FILE statement and PUT statements and once the SAS program is created you %INCLUDE it.
BR, Koen
Figure out how SAS stores the value for a MLF in a CNTLIN= dataset by making one by code and looking at the dataset generated by the CNTLOUT= option.
proc format cntlout=formats;
value myfmt (multilabel)
1 = "One"
2 = "Two"
3 = "Three"
4 = "Four"
5 = "Five"
1,3,5 = "Odd"
2,4 = "Even"
1-5 = "1-5"
;
run;
proc print data=formats;
var fmtname type start end label hlo sexcl eexcl ;
run;
So basically just add the extra observations you need and set the HLO variable 'SM'.
I notice that SAS has given the MYFMT format the NOTSORTED attribute in the CNTLOUT data set, HLO='SM' even though you did not specify NOTSORTED in the VALUE statement options list.
I did not expect that output.
@Tom wrote:
Figure out how SAS stores the value for a MLF in a CNTLIN= dataset by making one by code and looking at the dataset generated by the CNTLOUT= option.
proc format cntlout=formats; value myfmt (multilabel) 1 = "One" 2 = "Two" 3 = "Three" 4 = "Four" 5 = "Five" 1,3,5 = "Odd" 2,4 = "Even" 1-5 = "1-5" ; run; proc print data=formats; var fmtname type start end label hlo sexcl eexcl ; run;
So basically just add the extra observations you need and set the HLO variable 'SM'.
So, HLO=SM is what tells SAS this is a multi-label format? Not the most obvious solution I have ever encountered, but it does the trick -- thanks!
By the way -- where is this (and the other fields in that cntlout file) documented? Even The Google was perplexed
SAS Help Center: Results: PROC FORMAT
@dwaldo wrote:
So, HLO=SM is what tells SAS this is a multi-label format? Not the most obvious solution I have ever encountered, but it does the trick -- thanks!
By the way -- where is this (and the other fields in that cntlout file) documented? Even The Google was perplexed
I think this is a really good discussion if really good.
Multiple Facts about Multilabel Formats
@data_null__ wrote:
I notice that SAS has given the MYFMT format the NOTSORTED attribute in the CNTLOUT data set, HLO='SM' even though you did not specify NOTSORTED in the VALUE statement options list.
I did not expect that output....
I think that it what the paper you cited means when it talks about sorting.
Essentially when you using the LABEL statement of PROC FORMAT without the NOTSORTED option for a multilabel format it sorts by the START value and then generates the control dataset in that order and set the 'S' tag of the HLO variable to preserve it.
You can see it by replicating the AGE format from that paper.
proc format cntlout=formats;
value age (multilabel)
19-120='Adults'
1-18='Children'
1-4='Preschool'
;
value ages (multilabel notsorted)
19-120='Adults'
1-18='Children'
1-4='Preschool'
;
run;
data compare;
N+1;
set formats(where=(fmtname='AGE') rename=(start=AGE_START end=AGE_END label=AGE_LABEL));
set formats(where=(fmtname='AGES') rename=(start=AGES_START end=AGES_END label=AGES_LABEL));
run;
proc print;
var N age: ;
run;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.