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

hello,

in my work I often would like to report the data structure as a tree with nodes and subnodes.

I recently discovered odslist that seems to have the capacity to present information as a nested list.

for instance I can represent my data in a parent child structure as follows:

 

id parent n
G   100
G1 G 60
G11 G1 40
G12 G1 20
G2 G 10
G21 G2 10
G3 G 30
G31 G3 10
G32 G3 5
G33 G3 15

 

and I would like to represent tham in the following way:

G 100 records

              G1 60 records

                            G11 40 records

                            G12 20 records

              G2 10 records

                            G21 10 records

              G3 30 records

                            G31 10 records

                            G32 5 records

                            G33 15 records

 

Is it possible with odslist? any suggestion and especially code is very appreciated.

thanks in advance

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
infile cards expandtabs;
input id $	parent $	n;
idx=length(id);
have=catx(' ',id,n,'records');
cards;
G	 .	100
G1	G	60
G11	G1	40
G12	G1	20
G2	G	10
G21	G2	10
G3	G	30
G31	G3	10
G32	G3	5
G33	G3	15
;


proc report data=have nowd noheader style={frame=void rules=none};
column idx have;
define idx/display noprint;
compute have;
if idx=2 then call define(_col_,'style','style={indent=0.25in}');
if idx=3 then call define(_col_,'style','style={indent=0.5in}');
endcomp;
run;

Ksharp_0-1680006946541.png

 

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

@ciro wrote:

 

I recently discovered odslist that seems to have the capacity to present information as a nested list.


If you look at the documentation for PROC ODSLIST, you see this example:

Example 2: Creating Nested Lists

--
Paige Miller
ciro
Quartz | Level 8

dear Paige,

thank you for your answer.

I had read that example and others, but my problem is a bit different, I think as the sublists and level of 

indentation have to be initiated according to some conditions.

Ksharp
Super User
data have;
infile cards expandtabs;
input id $	parent $	n;
idx=length(id);
have=catx(' ',id,n,'records');
cards;
G	 .	100
G1	G	60
G11	G1	40
G12	G1	20
G2	G	10
G21	G2	10
G3	G	30
G31	G3	10
G32	G3	5
G33	G3	15
;


proc report data=have nowd noheader style={frame=void rules=none};
column idx have;
define idx/display noprint;
compute have;
if idx=2 then call define(_col_,'style','style={indent=0.25in}');
if idx=3 then call define(_col_,'style','style={indent=0.5in}');
endcomp;
run;

Ksharp_0-1680006946541.png

 

ciro
Quartz | Level 8

Thank you Ksharp. Very interesting solution. I learnt a new possibility.

I'd like to wait a little more for an odslist solution. 

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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
  • 4 replies
  • 1102 views
  • 3 likes
  • 3 in conversation