BookmarkSubscribeRSS Feed
Tommy1
Quartz | Level 8

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

4 REPLIES 4
PaigeMiller
Diamond | Level 26
tables Prior_Year*Current_Year/  out=test missing;
--
Paige Miller
Tommy1
Quartz | Level 8

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

Kurt_Bremser
Super User

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.

Tommy1
Quartz | Level 8

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 924 views
  • 2 likes
  • 3 in conversation