I am writing an IML module with 10 parameters defined. The first parameter is mandatory and the remaining nine are optional. I want to extract the names of numeric parameters.
If I use only nine parameters, I have no trouble using the parentname() function to access a parameter and store its name.
But if I use all 10 parameters, then I cannot extract the first nine and I can access only the tenth parameter.
The following code defines a module with 10 parameters and two test cases: the first test case uses nine parameters and works properly. The second test case uses 10 parameters and returns a blank for the parameter name which I change to a '.' for sake of visibility. In the second case, only the name of the last parameter is returned properly.
proc iml ;
reset noname spaces=1 ;
start test( p1, p2=, p3=, p4=, p5=, p6=, p7=, p8=, p9=, p10= ) ;
print '*** nine-parameter case ***' ;
free p parm_name ;
p = 'p1' : 'p9' ;
print p ;
do i = 1 to ncol( p ) ;
parm_value = parentname( p[ i ] ) ;
if parm_value = ' ' then parm_value = '.' ;
parm_name = parm_name || parm_value ;
end ;
print parm_name ;
print '*** 10-parameter case ***' ;
free p parm_name ;
p = 'p1' : 'p10' ;
print p ;
do i = 1 to ncol( p ) ;
parm_value = parentname( p[ i ] ) ;
if parm_value = ' ' then parm_value = '.' ;
parm_name = parm_name || parm_value ;
end ;
print parm_name ;
finish ;
a = 1 ; b = 2 ; c = 3 ; d = 4 ; e = 5 ;f = 6 ; g = 7 ; h = 8 ; i = 9 ; j = 10 ;
run test( a, b, c, d, e, f, g, h, i, j ) ;
quit ;
The output of the test() module is given below.
*** nine-parameter case ***
p1 p2 p3 p4 p5 p6 p7 p8 p9
a b c d e f g h i
*** 10-parameter case ***
p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
. . . . . . . . . j
In the first case, all parameter names are extracted and reported correctly. In the second case, apparently the parentname() function returns a blank value which I then convert to '.' for visibility for the first nine parameters and correctly returns the name of the tenth parameter correctly.
I am perplexed about this parameter passing property. Can anyone explain what is happening? Am I running into a limit on the number of IML module parameters?
/*
It is so interesting.
You can add STRIP() as the following.
p = 'p1' : 'p10' ;
would get these : ' p1' ' p2' ... 'p10',
note there is a blank before p1 p2 ...p9,that would give wrong name into SAS.
Surprise ??
but if you are using p='p1':'p9' would NOT generate that problem. Surprise ??
*/
proc iml ;
reset noname spaces=1 ;
start test( p1, p2=, p3=, p4=, p5=, p6=, p7=, p8=, p9=, p10= ) ;
print '*** nine-parameter case ***' ;
free p parm_name ;
p = 'p1' : 'p9' ;
print p ;
do i = 1 to ncol( p ) ;
parm_value = parentname( p[ i ] ) ;
if parm_value = ' ' then parm_value = '.' ;
parm_name = parm_name || parm_value ;
end ;
print parm_name ;
print '*** 10-parameter case ***' ;
free p parm_name ;
p = 'p1' : 'p10' ;
print p ;
do i = 1 to ncol( p ) ;
parm_value = parentname( strip(p[ i ]) ) ; /*<--------*/
if parm_value = ' ' then parm_value = '.' ;
parm_name = parm_name || parm_value ;
end ;
print parm_name ;
finish ;
a = 1 ; b = 2 ; c = 3 ; d = 4 ; e = 5 ;f = 6 ; g = 7 ; h = 8 ; i = 9 ; j = 10 ;
run test( a, b, c, d, e, f, g, h, i, j ) ;
quit ;
/*
It is so interesting.
You can add STRIP() as the following.
p = 'p1' : 'p10' ;
would get these : ' p1' ' p2' ... 'p10',
note there is a blank before p1 p2 ...p9,that would give wrong name into SAS.
Surprise ??
but if you are using p='p1':'p9' would NOT generate that problem. Surprise ??
*/
proc iml ;
reset noname spaces=1 ;
start test( p1, p2=, p3=, p4=, p5=, p6=, p7=, p8=, p9=, p10= ) ;
print '*** nine-parameter case ***' ;
free p parm_name ;
p = 'p1' : 'p9' ;
print p ;
do i = 1 to ncol( p ) ;
parm_value = parentname( p[ i ] ) ;
if parm_value = ' ' then parm_value = '.' ;
parm_name = parm_name || parm_value ;
end ;
print parm_name ;
print '*** 10-parameter case ***' ;
free p parm_name ;
p = 'p1' : 'p10' ;
print p ;
do i = 1 to ncol( p ) ;
parm_value = parentname( strip(p[ i ]) ) ; /*<--------*/
if parm_value = ' ' then parm_value = '.' ;
parm_name = parm_name || parm_value ;
end ;
print parm_name ;
finish ;
a = 1 ; b = 2 ; c = 3 ; d = 4 ; e = 5 ;f = 6 ; g = 7 ; h = 8 ; i = 9 ; j = 10 ;
run test( a, b, c, d, e, f, g, h, i, j ) ;
quit ;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.