As provided below, my dataset includes two classification variables: class1 and class2.
24 observations exist.
15 observations have a non-missing value of class1.
20 observations have a non-missing value of class2.
13 observations have non-missing values of class1 and class2.
When I run proc report as below, I would like to use 15 observations for the part of class1 and use 20 observations for the part of class2. But PROC REPORT uses the observations where there is no missing value of class1 and class 2. Is there a way to achieve what I describe? I just want to use the maximum sample for each variable, not the intersection.
data have;
input ID year class1 class2 @@;
datalines;
1 2000 1 1
2 2000 1 1
3 2000 1 2
4 2000 1 2
5 2000 2 1
6 2000 2 1
7 2000 2 2
8 2000 2 2
9 2000 . 2
10 2000 2 .
11 2000 . 2
12 2000 . .
1 2001 1 1
2 2001 1 1
3 2001 1 2
4 2001 . 2
5 2001 . 1
6 2001 . 1
7 2001 2 2
8 2001 2 2
9 2001 . 2
10 2001 2 .
11 2001 . 2
12 2001 . .
;
run;
proc means data= have; run;
proc report data= have;
columns year class1 class2;
define year / group ;
define class1/ across;
define class2/ across;
run;
SAS results are as follows:
class1 class2 year 1 2 1 2 2000 4 4 4 4 2001 3 2 2 3
What I would like to have:
class1 class2 year 1 2 1 2 2000 4 5 4 6 2001 3 3 4 6
Your DATA step code does not produce the correct data set. It looks like this:
Could you please provide working code for this data set?
@PaigeMiller The code posted in the original question now runs fine. So either it was edited or your method of copying it messed it up.
@Tom wrote:
@PaigeMiller The code posted in the original question now runs fine. So either it was edited or your method of copying it messed it up.
Well I beg to differ, I just pasted it into SAS Studio from here, and it sill doesn't give the desired data set. But I suppose its not really relevant now.
@PaigeMiller wrote:
@Tom wrote:
@PaigeMiller The code posted in the original question now runs fine. So either it was edited or your method of copying it messed it up.
Well I beg to differ, I just pasted it into SAS Studio from here, and it sill doesn't give the desired data set. But I suppose its not really relevant now.
The editor in SAS/Studio does not handle text the way the normal SAS editor does. For example if you open a file in the normal SAS editor that contains tabs and submit it the tabs are converted to spaces before it gets to the SAS parser. But in SAS/Studio the tabs will stay in the text sent to SAS to run.
So you probably have embedded some tabs or some other strange characters by copying and pasting directly into the SAS/Studio editor tab in your browser. It it is just tabs then try adding
infile cards expandtabs;
to the data step.
Yes, that's it, @Tom . Thanks!
If you add the MISSING option to the PROC REPORT statement then the observations with a missing value for one or more of the across variables will not be excluded.
proc report data= have missing;
columns year n,class1 n,class2;
define year / group ;
define class1/ across;
define class2/ across;
define n / ' ';
run;
class1 class2 year . 1 2 . 1 2 2000 3 4 5 2 4 6 2001 6 3 3 2 4 6
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.