BookmarkSubscribeRSS Feed
EC27556
Quartz | Level 8

Hi I am having some trouble getting my proc tab to output a missing value.

 

Here is the proc tab (for reference, the variable "one" is a variable that=1 for all observations):

 

proc tabulate data = Have out = Want;
class GroupA GroupB GroupC GroupD ap_month;
var count one;
table GroupA=''*GroupB=''*GroupC=''*GroupD=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge;
run;

 

Which gives a table that looks like this:

 

Table5.PNG

 

and output dataset that looks like this:

 

EC27556_0-1652272599494.png

 

However, in the table you can see a missing value. This missing value does not appear in the output dataset. You can see in between the highlighted rows, there is no 01/03/2021. Is there any way to make proc tabulate output a row in the output dataset for 01/03/2021, where one_sum would = .?

7 REPLIES 7
Cynthia_sas
SAS Super FREQ
Hi:
I think you need to investigate the PRINTMISS option of the TABLE statement. It's good to see your code but without some test data, no one can run your code.
Cynthia
mkeintz
PROC Star

@Cynthia_sas 

 

I think your suggestion of printmiss does it.   The want_printmiss dataset below has an observation corresponding to the missing cell in the table and absent from the want_normal dataset.

 

data have;
  input x y  ;
datalines;
1 1
1 2
2 1
run;
proc tabulate data=have out=want_normal;
  class x y  ;
  tables x,y  ;
run;
proc tabulate data=have out=want_printmiss;
  class x y  ;
  tables x,y  /printmiss;
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
EC27556
Quartz | Level 8

Hi, here is some example code:

data person;
   input GroupA GroupB GroupC ap_month $ one;
   datalines;
1 1 1 Jan2010 1
1 1 2 Jan2010 1
1 2 1 Jan2010 1
2 1 1 Jan2010 1
2 2 1 Jan2010 1

1 1 1 Jan2011 1
1 1 2 Jan2011 1
1 2 1 Jan2011 1
2 1 1 Jan2011 1

;
/*2 2 1 Jan2011 1*/
run;

proc tabulate data = Person out = want;
class GroupA GroupB GroupC ap_month;
var one;
table GroupA=''*GroupB=''*GroupC=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge ;
run;
proc tabulate data = Person out = want2;
class GroupA GroupB GroupC ap_month;
var one;
table GroupA=''*GroupB=''*GroupC=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge printmiss;
run;

Here you can see an example of the situation I have going on. You can see the commented out line is basically the missing data - which is then missing in the first proc tabulate table. By using printmiss, it expands the table (which i dont want) and, whilst the wanted output observation is now included in the output data, all the other observations relating to this bigger table are now also included - which i dont want!

Quentin
Super User

Try adding the MISSING option to the PROC TABULATE statement.

 

proc tabulate data = Have out = Want MISSING;
class GroupA GroupB GroupC GroupD ap_month;
var count one;
table GroupA=''*GroupB=''*GroupC=''*GroupD=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge;
run;

If that doesn't work, try adding it the CLASS statement

proc tabulate data = Have out = Want MISSING;
class GroupA GroupB GroupC GroupD ap_month / MISSING;
var count one;
table GroupA=''*GroupB=''*GroupC=''*GroupD=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge;
run;

See also other TABULATE options for dealings with missing, such as MISSPRINT and MISSTEXT.

BASUG is hosting free webinars Next up: Don Henderson presenting on using hash functions (not hash tables!) to segment data on June 12. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
EC27556
Quartz | Level 8

@mkeintz 

 

The missing option does not seem to help unfortunately.

 

Here is some example code:

data person;
   input GroupA GroupB GroupC ap_month $ one;
   datalines;
1 1 1 Jan2010 1
1 1 2 Jan2010 1
1 2 1 Jan2010 1
2 1 1 Jan2010 1
2 2 1 Jan2010 1

1 1 1 Jan2011 1
1 1 2 Jan2011 1
1 2 1 Jan2011 1
2 1 1 Jan2011 1

;
/*2 2 1 Jan2011 1*/
run;

proc tabulate data = Person out = want;
class GroupA GroupB GroupC ap_month;
var one;
table GroupA=''*GroupB=''*GroupC=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge ;
run;
proc tabulate data = Person out = want2;
class GroupA GroupB GroupC ap_month;
var one;
table GroupA=''*GroupB=''*GroupC=''*sum=''*(one*f=comma14.0),ap_month  /nocellmerge printmiss;
run;

Here you can see an example of the situation I have going on. You can see the commented out line is basically the missing data - which is then missing in the first proc tabulate table. By using printmiss, it expands the table (which i dont want) and, whilst the wanted output observation is now included in the output data, all the other observations relating to this bigger table are now also included - which i dont want!

Reeza
Super User

That's a missing category, not missing value. How does SAS know to add in something that doesn't exist in a data set? 

 

You can use a PRELOADFMT or CLASSDATA to add in categories that are missing/non existent in your data.

https://www.lexjansen.com/nesug/nesug11/cc/cc29.pdf

Tom
Super User Tom
Super User

Why are you using TABULATE instead of SUMMARY if the goal is a DATASET?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 7 replies
  • 904 views
  • 6 likes
  • 6 in conversation