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

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

@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

4 REPLIES 4
Astounding
PROC Star

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?

art297
Opal | Level 21

@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

 

Astounding
PROC Star

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.

no_hassles
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 831 views
  • 0 likes
  • 3 in conversation