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
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;
@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
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.
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;
Thank you Ksharp. Very interesting solution. I learnt a new possibility.
I'd like to wait a little more for an odslist solution.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.