BookmarkSubscribeRSS Feed
carslan
Calcite | Level 5

Hallo All,

I have the dataset reports with proc reports:
info CW is calendar-week

VAR1
01
VAR2VAR2
01 01
VAR3VAR3 VAR3VAR3
001001
CWsumsumsumsumsumsum
15W01120300152023

But I want to have the report like decision tree diagram:

CW VAR1
15W0143525
VAR2VAR2
120315205
VAR3VAR3VAR3VAR3
120300152023
sumsumsumsumsumsum
120300152023

And so, for15W01, 15W02, 15W03, ….

I have only SAS BASE 9.4.

 

Can anyone know how to get this Report? Any help would be greatly appreciated.

Many Thanks,

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

Hi:

  There are other procedures for SAS that do decision trees, but your example doesn't look like modeling. It looks more like a nested summary report. PROC REPORT and PROC TABULATE will both do summary reports, but won't "skip" variables on rows the way you show (such that VAR1 is in the middle. But, here's an example of what TABULATE would do for you (showing 15W01 only):

tab_nested_table.png

And, here's an example of what REPORT would do for you:

report_nested_table.png

But of course, since you didn't post any input data, I had to make some fake data. So the structure of your input data will make a difference to the final code for you. For example, given that you said this was weekly data, I made a fake "DAY" variable, which you might not have in your data.

SAS does have procedures that do decision trees (PROC DTREE), but that is more for modeling than what you seem to show (simple SUM).

cynthia

carslan
Calcite | Level 5

Hi Cynthia,

Thanks a lot for your support. Maybe my text was not clear.  here is the data for only CW 15W01

data decison;

    input CK $ VAR1 VAR2 VAR3 SUM;

    datalines;

15W01 0 0 0 120

15W01 0 1 0 300

15W01 0 1 1 15

15W01 1 0 0 20

15W01 1 1 0  2

15W01 1 1 1  3

  ;

run;

with proc report I have this table like your proc report table

proc_report.JPG

But I want to have this table.I want have SUM for every variable or class

last.JPG

I can do with 3 different proc report table. but I must do or show only one proc report table.

Thanks

Cynthia_sas
SAS Super FREQ

Hi:

  That is rather dicey to produce, since the header values are placed in PROC REPORT header cells, one row at a time. So, at the point in time AFTER the VAR1 has been written on header row 1 and AFTER the 1 and 0 have been written on header row 2, there is no visibility of the value that was just written in the previous row in order to write the 435 and the 25. So that will be a challenge you might get around with some kind of macro programming. But I do not think that this is really possible with PROC REPORT without at LOT of pre-processing of the data or the report. If you have presummarized all the totals, you might be able to do this with a custom TABLE template or with the Report Writing interface and a DATA step. But really, I am doubtful that PROC REPORT will be able to give you what you want. You might want to check with Tech Support before you start investigating other technology, though.

cynthia

TBarney
Fluorite | Level 6

Hey, I know that this post is almost 4 years old, however, I am looking into something along the same lines.  I have a Excel Template that displays data in a tree downward as subsets fo the the total. I was looking for Proc Report help to re-create this template, to reduce cut and paste to Excel.

What was you final solution?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1594 views
  • 0 likes
  • 3 in conversation