BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rbettinger
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
/*
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 ;    

Ksharp_0-1672050387979.png

 

View solution in original post

2 REPLIES 2
Ksharp
Super User
/*
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 ;    

Ksharp_0-1672050387979.png

 

rbettinger
Lapis Lazuli | Level 10
The line of code 'parm_value = parentname( strip(p[ i ]) ) ;' works as Ksharp indicated, I did not read his solution carefully enough. It was very perceptive of Mr. Ksharp to understand that SAS/IML adds a blank character to pad the character literals returned by the ':' function.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1259 views
  • 1 like
  • 2 in conversation