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 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 349 views
  • 2 likes
  • 3 in conversation