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

Hi all

 

I'm using the ODS Writing Interface to dynamically generate reports. The dataset (wide format) that I'm referencing has the correct format specified for each column. However, when using format_cell, the format doesn't appear to be attached to the variable specified.

 

As a workaround, I've used the PUT function to return the string with the specified format. It works if I hard code the format but I would like to dynamically pull the format from the variable I'm referencing.

 

This works:

obj.format_cell(data: PUT(VAR1, dollar10.2)) ;

 

I would like instead:

obj.format_cell(data: PUT(VAR1, %SYSFUNC(VFORMAT(VAR1))));

 

i.e. %SYSFUNC(VFORMAT(VAR1)) should equal dollar10.2

 

Result:

ERROR: The function VFORMAT referenced by %SYSFUNC, %QSYSFUNC, or %SYSCALL cannot be used within the MACRO function/call-routine interfaces.

 

Any thoughts on a fix? Similarly, I would like to replace VAR1 with an array element V(1).

 

Thanks for your help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Reeza
Super User
PUT()/PUTC() will take a variable as the second parameter.
ballardw
Super User

@Brian wrote:

Hi all

 

I'm using the ODS Writing Interface to dynamically generate reports. The dataset (wide format) that I'm referencing has the correct format specified for each column. However, when using format_cell, the format doesn't appear to be attached to the variable specified.

 

As a workaround, I've used the PUT function to return the string with the specified format. It works if I hard code the format but I would like to dynamically pull the format from the variable I'm referencing.

 

This works:

obj.format_cell(data: PUT(VAR1, dollar10.2)) ;

 

I would like instead:

obj.format_cell(data: PUT(VAR1, %SYSFUNC(VFORMAT(VAR1))));

 

i.e. %SYSFUNC(VFORMAT(VAR1)) should equal dollar10.2

 

Result:

ERROR: The function VFORMAT referenced by %SYSFUNC, %QSYSFUNC, or %SYSCALL cannot be used within the MACRO function/call-routine interfaces.

 

Any thoughts on a fix? Similarly, I would like to replace VAR1 with an array element V(1).

 

Thanks for your help!

 


SYSFUNC is to allow you to call data step functions in a macro. Since the RWI is part of a data step then there is no need to use SYSFUNC at all.

You will need to pay attention to how you pass the variable to VFORMAT which will not take an expression, requiring either the literal variable name or an array reference to variable so VFORMAT(V[1]) should work just fine assuming you have properly defined your array V.

 

Brian
Obsidian | Level 7

When I remove %SYSFUNC, I receive the following:

ERROR 85-322: Expecting a format name.

 

I hoped to use %SYSFUNC to resolve the format name first.

Reeza
Super User
You still need to use PUTC(), it won't work with the format otherwise.
Brian
Obsidian | Level 7

Thank you everyone for your help. Have a great day!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1504 views
  • 3 likes
  • 3 in conversation