DATA Step, Macro, Functions and more

formatted variables not accepting format label value

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

formatted variables not accepting format label value

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:

 

FORMAT NAME dollarsignCPT2CSS.png

 

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.

 

 

proc_grp_desc_data.png

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


Accepted Solutions
Solution
‎03-21-2017 02:16 PM
PROC Star
Posts: 7,467

Re: formatted variables not accepting format label value

Posted in reply to Astounding

@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

 

View solution in original post


All Replies
Super User
Posts: 5,495

Re: formatted variables not accepting format label value

Posted in reply to no_hassles

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?

Solution
‎03-21-2017 02:16 PM
PROC Star
Posts: 7,467

Re: formatted variables not accepting format label value

Posted in reply to Astounding

@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

 

Super User
Posts: 5,495

Re: formatted variables not accepting format label value

Art,

 

I think that your test shows this combination of factors at work:

 

  • The PUT statement uses a character value for the first argument, but a numeric format in the second argument.
  • To make the types match, SAS automatically assumes it should look for that format name with a $ in front of it.

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.

Occasional Contributor
Posts: 10

Re: formatted variables not accepting format label value

[ Edited ]
Posted in reply to Astounding

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

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 114 views
  • 0 likes
  • 3 in conversation