DATA Step, Macro, Functions and more

Two-way proc freq not showing transition to missing?

Reply
Contributor
Posts: 21

Two-way proc freq not showing transition to missing?

Hi SAS Community,

 

I am currently running a Proc Freq to create a two way table. When I run the procedure using the code below, it creates a table, but it does not include the transition from having a value to missing.

 

proc freq data=new;
tables Prior_Year*Current_Year/  out=test;
run;

An example of what my data looks like is 

Prior_Year       Current_Year

1                      2

1                      3

1                      2

1                      

In this example, I would expect out=test to look like

Prior Year        Current_year        Count

1                      2                           2

1                      3                           1

1                                                   1

but, it does not include the transition from 1 to when there is null in the Current_Year column. Does anyone know an option or technique that I can use to include the count of the values that start in the Prior_Year but are missing in the Current_Year. I tried the missing option, but that didn't do anything.

 

If anybody could help I would greatly appreciate it!

 

Thanks,

Tom

Respected Advisor
Posts: 3,293

Re: Two-way proc freq not showing transition to missing?

[ Edited ]
tables Prior_Year*Current_Year/  out=test missing;
--
Paige Miller
Contributor
Posts: 21

Re: Two-way proc freq not showing transition to missing?

Posted in reply to PaigeMiller

Thanks, I tried that already and it still doesn't give me the missing values. It also isn't giving me all the possible combinations like it is supposed to.

 

Thanks,

Tom

Super User
Posts: 10,623

Re: Two-way proc freq not showing transition to missing?

Given your example data, it works:

data have;
input Prior_Year Current_Year;
cards;
1 2
1 3
1 2
1 .
;
run;

proc freq data=have noprint;
tables Prior_Year*Current_Year/ missing out=want;
run;

proc print data=want noobs;
run;

Result:

Prior_    Current_
 Year       Year      COUNT    PERCENT

   1          .         1         25  
   1          2         2         50  
   1          3         1         25  

Just the order is different.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 21

Re: Two-way proc freq not showing transition to missing?

Posted in reply to KurtBremser

Thanks for your help. You are right, I sorted my results by Current_Year and there was one instance where the Current_Year =. . It seems like the issue is somewhere in my data because there should be many more occurrences where there are transitions to null. I apologize for wasting anybody's time.

Thanks,

Tom

Ask a Question
Discussion stats
  • 4 replies
  • 96 views
  • 2 likes
  • 3 in conversation