Ow boy, I have been struggling a while to get the result i want, but untill now I did not succeed. I'm trying to produce a report with multiple across variables with different levels but would like the output always be the same, independent of the values in the dataset. I have found the options nozero but this excludes missing values (great) but also the 0-values (not great since in pre-processing the dataset i make sure that every combination is avalaible, but with a measure = 0).
This code creates a sample dataset. Two people, three groups, one measure.
data test;
attrib
id length = 8.
naam length = $50.
groep1 length = $50.
groep2 length = $50.
groep3 length = $50.
overtreding length = 8.;
id=1;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=2;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=3;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='hbi';overtreding=1;;output;
id=4;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='ki';overtreding=1;output;
id=5;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='bi';overtreding=1;output;
id=6;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='hbi';overtreding=1;output;
id=7;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='ki';overtreding=1;output;
id=8;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='bi';overtreding=1;output;
id=9;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='hbi';overtreding=0;output;
id=10;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=11;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=12;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=1;naam = 'Charlie';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=2;naam = 'Charlie';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=3;naam = 'Charlie';groep1 = 'Dagelijks';groep2='norm8';groep3='hbi';overtreding=1;output;
id=4;naam = 'Charlie';groep1 = 'Dagelijks';groep2='norm10';groep3='ki';overtreding=1;output;
id=5;naam = 'Charlie';groep1 = 'Dagelijks';groep2='norm10';groep3='bi';overtreding=1;output;
id=6;naam = 'Charlie';groep1 = 'Dagelijks';groep2='norm10';groep3='hbi';overtreding=1;output;
id=7;naam = 'Charlie';groep1 = 'Wekelijks';groep2='x';groep3='ki';overtreding=1;output;
id=8;naam = 'Charlie';groep1 = 'Wekelijks';groep2='x';groep3='bi';overtreding=1;output;
id=9;naam = 'Charlie';groep1 = 'Wekelijks';groep2='x';groep3='hbi';overtreding=0;output;
id=10;naam = 'Charlie';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=11;naam = 'Charlie';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=12;naam = 'Charlie';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
/* id=1;naam = 'dummy';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output; */
/* id=3;naam = 'dummy';groep1 = 'Dagelijks';groep2='norm8';groep3='hbi';overtreding=1;output; */
/* id=4;naam = 'dummy';groep1 = 'Dagelijks';groep2='norm10';groep3='ki';overtreding=1;output; */
/* id=5;naam = 'dummy';groep1 = 'Dagelijks';groep2='norm10';groep3='bi';overtreding=1;output; */
/* id=6;naam = 'dummy';groep1 = 'Dagelijks';groep2='norm10';groep3='hbi';overtreding=1;output; */
/* id=7;naam = 'dummy';groep1 = 'Wekelijks';groep2='x';groep3='ki';overtreding=1;output; */
/* id=8;naam = 'dummy';groep1 = 'Wekelijks';groep2='x';groep3='bi';overtreding=1;output; */
/* id=9;naam = 'dummy';groep1 = 'Wekelijks';groep2='x';groep3='hbi';overtreding=0;output; */
/* id=12;naam = 'dummy';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output; */
run;
If I create a proc report without the option nozero i get this
This looks like what I want but there are several "combinations" of the across variables that have missing values. So i added the option "nozero" but this also deletes columns with a total of 0 (ahum, offcourse), and so the report is missing a column. I would like all output reports to look the same.
I have tried several approaches, for example the option to work with preloadfmt, but none of this is working or me.....
Is there anybody who can give me some advice in solving this case?
Any help is appreciated.
If you just want to exclude the missing columns but include the zero values then add some insignificant value to so the zeros are no longer exactly zero.
First let's make your example two person dataset. Notice how much easier it is to share data with in-line data?
data test;
input id naam :$50. (groep1-groep3) (:$50.) overtreding ;
cards;
1 Dennis Dagelijks norm8 ki 1
2 Dennis Dagelijks norm8 ki 1
3 Dennis Dagelijks norm8 hbi 1
4 Dennis Dagelijks norm10 ki 1
5 Dennis Dagelijks norm10 bi 1
6 Dennis Dagelijks norm10 hbi 1
7 Dennis Wekelijks x ki 1
8 Dennis Wekelijks x bi 1
9 Dennis Wekelijks x hbi 0
10 Dennis Pauze x ki 1
11 Dennis Pauze x ki 1
12 Dennis Pauze x ki 1
1 Charlie Dagelijks norm8 ki 1
2 Charlie Dagelijks norm8 ki 1
3 Charlie Dagelijks norm8 hbi 1
4 Charlie Dagelijks norm10 ki 1
5 Charlie Dagelijks norm10 bi 1
6 Charlie Dagelijks norm10 hbi 1
7 Charlie Wekelijks x ki 1
8 Charlie Wekelijks x bi 1
9 Charlie Wekelijks x hbi 0
10 Charlie Pauze x ki 1
11 Charlie Pauze x ki 1
12 Charlie Pauze x ki 1
;
Now let's try the original report with NOZERO option. Then make a version of the data where 0.001 is added to the analysis variable. let's also attach a format so SAS will not show the fractional part.
proc report data=test;
title 'Original Data - With NOZERO option';
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group " " order = data;
define groep1-groep3 / across " " nozero;
define overtreding / ' ';
run;
data for_report;
set test;
overtreding+0.001;
format overtreding 5.;
run;
proc report data=for_report;
title 'Modified Data - With NOZERO option';
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group " " order = data;
define groep1-groep3 / across " " nozero;
define overtreding / ' ';
run;
title;
Results:
Please provide your PROC REPORT code as text and not as a screen capture.
/* code with nozero */
data test;
attrib
id length = 8.
naam length = $50.
groep1 length = $50.
groep2 length = $50.
groep3 length = $50.
overtreding length = 8.;
id=1;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=2;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=3;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='hbi';overtreding=1;;output;
id=4;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='ki';overtreding=1;output;
id=5;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='bi';overtreding=1;output;
id=6;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='hbi';overtreding=1;output;
id=7;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='ki';overtreding=1;output;
id=8;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='bi';overtreding=1;output;
id=9;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='hbi';overtreding=0;output;
id=10;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=11;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=12;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
run;
proc report data=work.test split='\' NOCENTER;
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group "" order = data;
define groep1 / across nozero "";
define groep2 / across nozero "";
define groep3 / across nozero "";
define overtreding / '';
run;
data test;
attrib
id length = 8.
naam length = $50.
groep1 length = $50.
groep2 length = $50.
groep3 length = $50.
overtreding length = 8.;
id=1;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=2;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='ki';overtreding=1;output;
id=3;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm8';groep3='hbi';overtreding=1;;output;
id=4;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='ki';overtreding=1;output;
id=5;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='bi';overtreding=1;output;
id=6;naam = 'Dennis';groep1 = 'Dagelijks';groep2='norm10';groep3='hbi';overtreding=1;output;
id=7;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='ki';overtreding=1;output;
id=8;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='bi';overtreding=1;output;
id=9;naam = 'Dennis';groep1 = 'Wekelijks';groep2='x';groep3='hbi';overtreding=0;output;
id=10;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=11;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
id=12;naam = 'Dennis';groep1 = 'Pauze';groep2='x';groep3='ki';overtreding=1;output;
run;
proc report data=work.test split='\' NOCENTER;
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group "" order = data;
define groep1 / across "";
define groep2 / across "";
define groep3 / across "";
define overtreding / '';
run;
Try the COMPLETECOLS option
proc report data=work.test split='\' NOCENTER completecols;
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group "" order = data;
define groep1 / across "";
define groep2 / across "";
define groep3 / across "";
define overtreding / '';
run;
If you just want to exclude the missing columns but include the zero values then add some insignificant value to so the zeros are no longer exactly zero.
First let's make your example two person dataset. Notice how much easier it is to share data with in-line data?
data test;
input id naam :$50. (groep1-groep3) (:$50.) overtreding ;
cards;
1 Dennis Dagelijks norm8 ki 1
2 Dennis Dagelijks norm8 ki 1
3 Dennis Dagelijks norm8 hbi 1
4 Dennis Dagelijks norm10 ki 1
5 Dennis Dagelijks norm10 bi 1
6 Dennis Dagelijks norm10 hbi 1
7 Dennis Wekelijks x ki 1
8 Dennis Wekelijks x bi 1
9 Dennis Wekelijks x hbi 0
10 Dennis Pauze x ki 1
11 Dennis Pauze x ki 1
12 Dennis Pauze x ki 1
1 Charlie Dagelijks norm8 ki 1
2 Charlie Dagelijks norm8 ki 1
3 Charlie Dagelijks norm8 hbi 1
4 Charlie Dagelijks norm10 ki 1
5 Charlie Dagelijks norm10 bi 1
6 Charlie Dagelijks norm10 hbi 1
7 Charlie Wekelijks x ki 1
8 Charlie Wekelijks x bi 1
9 Charlie Wekelijks x hbi 0
10 Charlie Pauze x ki 1
11 Charlie Pauze x ki 1
12 Charlie Pauze x ki 1
;
Now let's try the original report with NOZERO option. Then make a version of the data where 0.001 is added to the analysis variable. let's also attach a format so SAS will not show the fractional part.
proc report data=test;
title 'Original Data - With NOZERO option';
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group " " order = data;
define groep1-groep3 / across " " nozero;
define overtreding / ' ';
run;
data for_report;
set test;
overtreding+0.001;
format overtreding 5.;
run;
proc report data=for_report;
title 'Modified Data - With NOZERO option';
columns ('Chauffeur' naam) (groep1,groep2,groep3,(Overtreding));
define naam / group " " order = data;
define groep1-groep3 / across " " nozero;
define overtreding / ' ';
run;
title;
Results:
TOM!! It works. That's so clever.
You made my day. Thank you so much for your time and solution.
data test; input id naam :$50. (groep1-groep3) (:$50.) overtreding ; char_overtreding=put(overtreding,best. -l); cards; 1 Dennis Dagelijks norm8 ki 1 2 Dennis Dagelijks norm8 ki 1 3 Dennis Dagelijks norm8 hbi 1 4 Dennis Dagelijks norm10 ki 1 5 Dennis Dagelijks norm10 bi 1 6 Dennis Dagelijks norm10 hbi 1 7 Dennis Wekelijks x ki 1 8 Dennis Wekelijks x bi 1 9 Dennis Wekelijks x hbi 0 10 Dennis Pauze x ki 1 11 Dennis Pauze x ki 1 12 Dennis Pauze x ki 1 1 Charlie Dagelijks norm8 ki 1 2 Charlie Dagelijks norm8 ki 1 3 Charlie Dagelijks norm8 hbi 1 4 Charlie Dagelijks norm10 ki 1 5 Charlie Dagelijks norm10 bi 1 6 Charlie Dagelijks norm10 hbi 1 7 Charlie Wekelijks x ki 1 8 Charlie Wekelijks x bi 1 9 Charlie Wekelijks x hbi 0 10 Charlie Pauze x ki 1 11 Charlie Pauze x ki 1 12 Charlie Pauze x ki 1 ; proc report data=test nowd; columns ('Chauffeur' naam) (groep1,groep2,groep3,(char_overtreding)); define naam / group " " order = data; define groep1-groep3 / across " " ; define char_overtreding / group '' nozero; run;
Hi KSharp! That's also an option. But I have already implemented Tom' solution because I wanted summary totals (rows/columns) in the report.
But thank you for your reply!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.