BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Batman
Quartz | Level 8

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'

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.));

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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.));
Batman
Quartz | Level 8
proc format;
value $plan_type
'01'='HMO'
'02'='HMOPOS'
'04'='Local PPO'
'31'='Regional PPO'
;
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

sas-innovate-white.png

Special offer for SAS Communities members

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.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 693 views
  • 2 likes
  • 3 in conversation