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

Continuing the conversation re: representing an IML list structure as a matrix, how do I determine the position of the item L3_4 in the following example:

proc iml ; package load ListUtil ;
L = [ #'L1'=[ #'L1_1' = [ #'L1_2' = 'item L1_2' ] ]
    , #'L2'=[ #'L2_1' = 'item L2_1']
    , #'L3'=[ #'L3_1 '= [ #'L3_2' = [ #'L3_3' = [ #'L3_4'= 'item L3_4' ] ] ] ]
    ] ;
call struct(L) ;
call listprint( L ) ;
quit ;

If I want to delete item L$'L3'$'L3_1'$'L3_2'$'L3_3'$'L3_4', how do I use ListDeleteItem() to do this? How do I represent the position as a numeric matrix of indices or a character matrix of item names? Is my confusion due to the fact that I am trying to delete an item from a sublist? If so, how do I delete an item from a sublist?

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I feel like we might have had this conversation already?

Yes, I think your confusion is because you are trying to directly delete from a sublist. You can't use ListDeleteItem for that. The easiest way to delete an item from a sublist is to use ListGetSubItem with the 'd' flag:

proc iml ; package load ListUtil ;
L = [ #'L1'=[ #'L1_1' = [ #'L1_2' = 'item L1_2' ] ] ];
call struct(L) ;

item = ListGetSubItem(L, {'L1' 'L1_1' 'L1_2'}, 'd' );  /* get value; delete from the list */
free item;  /* optional: completely delete the item */
call struct(L) ;

View solution in original post

1 REPLY 1
Rick_SAS
SAS Super FREQ

I feel like we might have had this conversation already?

Yes, I think your confusion is because you are trying to directly delete from a sublist. You can't use ListDeleteItem for that. The easiest way to delete an item from a sublist is to use ListGetSubItem with the 'd' flag:

proc iml ; package load ListUtil ;
L = [ #'L1'=[ #'L1_1' = [ #'L1_2' = 'item L1_2' ] ] ];
call struct(L) ;

item = ListGetSubItem(L, {'L1' 'L1_1' 'L1_2'}, 'd' );  /* get value; delete from the list */
free item;  /* optional: completely delete the item */
call struct(L) ;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

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.

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