BookmarkSubscribeRSS Feed
Not_Sus
Calcite | Level 5

I want to dynamically change the place where a proc gchart gets displayed, because the number of entries in another report changes, and with it its size. The size the gchart should have is given by the input() statement in the last line. The ODS Region variable seems to not accept calculated values. Is there a way to solve this?

%macro get_table_size(inset,macvar);
 data _null_;
  set &inset NOBS=size;
  call symput("&macvar",size);
 stop; 
 run;
%mend;

%let reccount=;
%get_table_size(OI_SORTED_desc_CM,reccount);
%put (&reccount*0.5)+4.91;

*height = 18.41cm;
ODS Region  width = 7cm height = input((&reccount*0.5)+4.91,8.0) cm x = 13cm y = 5.05cm;

Log:

452        %get_table_size(OI_SORTED_desc_CM,reccount);
 SYMBOLGEN:  Makrovariable INSET wird in OI_SORTED_desc_CM aufgelöst
 SYMBOLGEN:  Makrovariable MACVAR wird in reccount aufgelöst
 
 NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       452:63   
 NOTE: There were 1 observations read from the data set WORK.OI_SORTED_DESC_CM.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 SYMBOLGEN:  Makrovariable RECCOUNT wird in           28 aufgelöst
 453        %put (&reccount*0.5)+4.91;
 (          28*0.5)+4.91
 454        
 455        
 456        
 457        *height = 18.41cm;
 458        ODS Region  width = 7cm height =
 458      ! input((&reccount*0.5)+4.91,8.0) cm x = 13cm y = 5.05cm;
            _____
            22
 SYMBOLGEN:  Makrovariable RECCOUNT wird in           28 aufgelöst
 458                                         input((&reccount*0.5)+4.91,8.0) cm x = 13cm y = 5.05cm;
                                             _____
                                             76
 ERROR 22-322: Expecting eine numerische Konstante.  
 ERROR 76-322: Syntax error, statement will be ignored.
2 REPLIES 2
ballardw
Super User

Calculate the whole value needed when creating the macro variable value.

Perhaps

%macro get_table_size(inset,macvar);
 data _null_;
  set &inset NOBS=size;
  call symput("&macvar", (size*0.5)+4.91);
 stop; 
 run;
%mend;

Note that data step, if NOBS is large repeats the exact same operation LOTS of times. You likely should add OBS=1 to the set statement so the step only executes one time.

 

How sure are you that 0.01 cm is going to make a difference in appearance in the output document?

 

I seriously doubt that the ODS REGION statement allows data step functions in the definition. The documentation talks about numbers, not function calls.

You might get away with using %sysevalf(<calculation bit goes here>) but it would still be better to set that value at creation time in the data step.

 


@Not_Sus wrote:

I want to dynamically change the place where a proc gchart gets displayed, because the number of entries in another report changes, and with it its size. The size the gchart should have is given by the input() statement in the last line. The ODS Region variable seems to not accept calculated values. Is there a way to solve this?

%macro get_table_size(inset,macvar);
 data _null_;
  set &inset NOBS=size;
  call symput("&macvar",size);
 stop; 
 run;
%mend;

%let reccount=;
%get_table_size(OI_SORTED_desc_CM,reccount);
%put (&reccount*0.5)+4.91;

*height = 18.41cm;
ODS Region  width = 7cm height = input((&reccount*0.5)+4.91,8.0) cm x = 13cm y = 5.05cm;

Log:

452        %get_table_size(OI_SORTED_desc_CM,reccount);
 SYMBOLGEN:  Makrovariable INSET wird in OI_SORTED_desc_CM aufgelöst
 SYMBOLGEN:  Makrovariable MACVAR wird in reccount aufgelöst
 
 NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
       452:63   
 NOTE: There were 1 observations read from the data set WORK.OI_SORTED_DESC_CM.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 SYMBOLGEN:  Makrovariable RECCOUNT wird in           28 aufgelöst
 453        %put (&reccount*0.5)+4.91;
 (          28*0.5)+4.91
 454        
 455        
 456        
 457        *height = 18.41cm;
 458        ODS Region  width = 7cm height =
 458      ! input((&reccount*0.5)+4.91,8.0) cm x = 13cm y = 5.05cm;
            _____
            22
 SYMBOLGEN:  Makrovariable RECCOUNT wird in           28 aufgelöst
 458                                         input((&reccount*0.5)+4.91,8.0) cm x = 13cm y = 5.05cm;
                                             _____
                                             76
 ERROR 22-322: Expecting eine numerische Konstante.  
 ERROR 76-322: Syntax error, statement will be ignored.

 

 

Quentin
Super User

You don't need the INPUT function.  The macro language is not great for doing arithmetic, but it can do integer arithmetic with the help of %eval, and floating point arithmentic with %sysevalf.

 

Consider:

1    %let reccount=28;
2    %put (&reccount*0.5)+4.91;
(28*0.5)+4.91
3    %put %sysevalf((&reccount*0.5)+4.91);
18.91

So I would think

ODS Region  width = 7cm height = %sysevalf((&reccount*0.5)+4.91)cm x = 13cm y = 5.05cm;

should work.

The Boston Area SAS Users Group (BASUG) is hosting an in person Meeting & Training on June 27!
Full details and registration info at https://www.basug.org/events.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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