Can I assign a macro value with a format. I'm able to do it in a data step, but similar code doesn't seem to work with a macro value.
27 /*value is correctly assigned in data step*/
28 data _null_;
29 y=put('01',$plan_type.);
30 put y;
31 run;
HMO
NOTE: DATA statement used (Total process time):
real time 0.15 seconds
cpu time 0.00 seconds
31 !
32
33 /*Doesn't work for macro value*/
34 %let grp=%sysfunc(putc('01',$plan_type.));
35 %put &grp;
'01'
Show us the definition of the format $PLAN_TYPE.
Does it actually include decodes for both of those values you tried?
In the data step you asked it to decode the two character string: 01. In the macro code you asked it do decode the four character string '01'.
Try it passing just the string 01 in the macro code.
%let grp=%sysfunc(putc(01,$plan_type.));
Show us the definition of the format $PLAN_TYPE.
Does it actually include decodes for both of those values you tried?
In the data step you asked it to decode the two character string: 01. In the macro code you asked it do decode the four character string '01'.
Try it passing just the string 01 in the macro code.
%let grp=%sysfunc(putc(01,$plan_type.));
You want
%let grp=%sysfunc(putc(01,$plan_type.));
%put &=grp;
You can't put quotes around 01 as you did originally, because in %sysfunc, everything is considered text and so quotes are considered text and not the demarcation of text. Thus '01' is a four character text string that does not match any of your format levels.
With regard to this
proc format;
value $plan_type
'01'='HMO'
'02'='HMOPOS'
'04'='Local PPO'
'31'='Regional PPO'
;
do yourself a favor and do us a favor and end all PROCs with a RUN; statement. And as mentioned above, show us all relevant parts of the code in your original post, don't leave relevant parts out.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.