BookmarkSubscribeRSS Feed
braam
Quartz | Level 8

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

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Your DATA step code does not produce the correct data set. It looks like this:

2020-02-01 14_29_23-Window.png

 

Could you please provide working code for this data set?

--
Paige Miller
Tom
Super User Tom
Super User

@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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Tom
Super User Tom
Super User

@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.

PaigeMiller
Diamond | Level 26

Yes, that's it, @Tom . Thanks!

--
Paige Miller
Tom
Super User Tom
Super User

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

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

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.

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
  • 6 replies
  • 711 views
  • 1 like
  • 3 in conversation