I created a user defined format using the cntlin method.
DATA aa.cpt_ccs_desc_fmt;
SET aa.cpt_ccs_desc_file;
RETAIN FMTNAME '$CPT2CSSD';
RENAME CCS = START CCS_Label = LABEL;
RUN;
PROC FORMAT library=library CNTLIN=aa.cpt_ccs_desc_fmt;
RUN;
The results look like this:
when I run the following code:
7 DATA aa.apd_op_1stqtr16_w_proc_grp_desc;
8 SET aa.apd_op_1stqtr16_w_proc_grp_freq;
9 length proc_grp_desc $ 30;
10 proc_grp_desc = put(procedure_group,$cpt2cssd.);
11 RUN;
NOTE: There were 16688 observations read from the data set AA.APD_OP_1STQTR16_W_PROC_GRP_FREQ.
NOTE: The data set AA.APD_OP_1STQTR16_W_PROC_GRP_DESC has 16688 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.01 seconds
My data looks like the following.
I would like the proc_grp_desc variable to assume the value of the format $cpt2cssd. label.
I have also tried doing this with a numberic format with similar results.
54 DATA aa.apd_op_1stqtr16_w_proc_grp_desc;
55 SET aa.apd_op_1stqtr16_w_proc_grp_freq;
56 length proc_grp_desc $ 30;
57 proc_grp_desc = put(procedure_group, cpt2cssd.);
58 RUN;
NOTE: There were 16688 observations read from the data set AA.APD_OP_1STQTR16_W_PROC_GRP_FREQ.
NOTE: The data set AA.APD_OP_1STQTR16_W_PROC_GRP_DESC has 16688 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Same data as shown above.
Does anyone have a better approach. Should I build the format using the traditional PROC FORMAT; VALUE this = that; RUN;
Stephen Dybas
@Astounding: My guess is that you're correct in thinking it's the 'library' specification.
However I, too, was surprised about the use of a numeric format for a character variable. However, to my surprise, the following worked:
data cpt_ccs_desc_file; informat ccs $3.; informat ccs_label $30.; input ccs ccs_label &; cards; 211 Therapeutic Radiology 213 Physical Therapy Exercises, Manipulation ; DATA cpt_ccs_desc_fmt; SET cpt_ccs_desc_file; RETAIN FMTNAME '$CPT2CSSz'; RENAME CCS = START CCS_Label = LABEL /*type 'C'*/; RUN; PROC FORMAT library=work CNTLIN=cpt_ccs_desc_fmt; RUN; data have; input procedure_group $; cards; 211 213 219 ; data want; set have; length proc_grp_desc $ 30; proc_grp_desc = put(procedure_group, cpt2cssz.); run;
Art, CEO, AnalystFinder.com
First thing to check: can your program locate the proper format. Since you are storing this format within the LIBRARY catalog, you must make the format available to the program by specifying:
options fmtsearch=LIBRARY;
If this is already in effect, then the problem becomes much messier. For example, there might be unprintable characters (within either the data or the format) such as hex nulls instead of blanks that result in a match not being found.
Also note, there might be a format with the same name in the WORK format library. That needs to be explored and eliminated as a possibility.
Finally, it seems very strange that you could run with either the numeric or the character format on the same variable, and not get an error message. Are you showing all the log notes?
@Astounding: My guess is that you're correct in thinking it's the 'library' specification.
However I, too, was surprised about the use of a numeric format for a character variable. However, to my surprise, the following worked:
data cpt_ccs_desc_file; informat ccs $3.; informat ccs_label $30.; input ccs ccs_label &; cards; 211 Therapeutic Radiology 213 Physical Therapy Exercises, Manipulation ; DATA cpt_ccs_desc_fmt; SET cpt_ccs_desc_file; RETAIN FMTNAME '$CPT2CSSz'; RENAME CCS = START CCS_Label = LABEL /*type 'C'*/; RUN; PROC FORMAT library=work CNTLIN=cpt_ccs_desc_fmt; RUN; data have; input procedure_group $; cards; 211 213 219 ; data want; set have; length proc_grp_desc $ 30; proc_grp_desc = put(procedure_group, cpt2cssz.); run;
Art, CEO, AnalystFinder.com
Art,
I think that your test shows this combination of factors at work:
You could try the same program, but removing the dollar sign here:
retain fmtname 'CPT2CSSz';
I would expect you get an error because there is no $CPT2CSSz format.
At any rate, at least there's an explanation for there being no error message in the original post.
Thank you everyone for your responces. I will carefully look at each one and develop a solutions to my issue.
Update:
I noticed that I built a numeric format while I thought I was building a character format. I changed my numeric start value to character start values and I was able to match values by the correct type and assign the format label to my new variable name.
Stephen Dybas
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.