BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mmaleta851
Fluorite | Level 6

Suppose I am running the following sales firm:

 

data work.table;
input Name:$24. Date:YYQ8. Trips Sales;
format Name $24. Date YYQ8.;
datalines;
John 2021Q1 10 100
John 2021Q3 2 200
John 2021Q4 4 400
David 2021Q1 16 300
David 2021Q2 8 600
David 2021Q4 19 100
Tim . 0 .
Karen 2021Q1 20 500
Jen . 0 .
;
run;

If a sales rep drove a trip that led to a sale at some point during 2021, they get credit for the trips and sales they drove during that quarter. If a rep did not drive a trip, the date and sales columns are null and trips are listed as 0. John, David, and Karen all drove trips in 2021 while Tim and Jen did not. Suppose I want to tabulate a report to see how many trips and sales were driven each quarter and what the contribution of each sales rep was. I want to include reps that did not drive any trips, so I run the following code:

 

proc tabulate data=work.table;
class Name Date / missing;
var Trips Sales;
tables Name All="Grand Total", (Date="" ALL="Grand Total")*(Trips*(sum=''*f=6.0) Sales*(sum=''*f=DOLLAR12.));
run;

The problem is that while I get missing values for Tim and Jen, I also get a missing value as a column as well:

 

mmaleta851_0-1673656560667.png

Is there a way that I run proc tabulate with the missing values for Tim and Jen without the missing value column. Alternatively is there a way I can create an additional column to indicate that Tim and Jen have no date values?

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@mmaleta851 wrote:

Patrick_1-1673663117048.png

 

Hey Patrick, I want to get rid of the Missing data columns, but I want to keep the rows that have missing data to indicate which sales reps did not complete any sales in 2021.


 

Then below should work.

proc sql;
  create table work._classdata as
  select distinct
    name,
    max(date) as date format=YYQ8.
  from work.table
  ;
quit;

options missing=' ';
proc tabulate data=work.table classdata=work._classdata;
  where not (missing(date) and missing(sales));
  class Name Date;
  var Trips Sales;
  tables 
    Name All="Grand Total", 
    (Date="" ALL="Grand Total")*(Trips*(sum=''*f=6.0) Sales*(sum=''*f=DOLLAR12.));
run;

Patrick_0-1673693426915.png

 

View solution in original post

8 REPLIES 8
Patrick
Opal | Level 21

Does one of below two options return what you're after?

options missing=' ';
proc tabulate data=work.table;
  where not (missing(date) and missing(sales));
  class Name Date / missing;
  var Trips Sales;
  tables 
    Name All="Grand Total", 
    (Date="" ALL="Grand Total")*(Trips*(sum=''*f=6.0) Sales*(sum=''*f=DOLLAR12.));
run;

Patrick_0-1673663083692.png

proc format;
  value date_cat
    . = 'missing date'
    other=[YYQ8.]
    ;
run;
options missing=' ';
proc tabulate data=work.table;
  format date date_cat.;
  class Name Date / missing;
  var Trips Sales;
  tables 
    Name All="Grand Total", 
    (Date="" ALL="Grand Total")*(Trips*(sum=''*f=6.0) Sales*(sum=''*f=DOLLAR12.));
run;

Patrick_1-1673663117048.png

 

 

 

mmaleta851
Fluorite | Level 6
The second one but without the missing date column.
Patrick
Opal | Level 21

@mmaleta851 wrote:
The second one but without the missing date column.

Then wouldn't that be the first one? If not then can you please copy/paste a screenshot of the 2nd report where you highlight what needs to be removed?

mmaleta851
Fluorite | Level 6

Patrick_1-1673663117048.png

 

Hey Patrick, I want to get rid of the Missing data columns, but I want to keep the rows that have missing data to indicate which sales reps did not complete any sales in 2021.

mmaleta851
Fluorite | Level 6

Basically I want something like this:

 

 2021Q1 2021Q2 2021Q3 2021Q4 Grand Total 
 TripsSalesTripsSalesTripsSalesTripsSalesTripsSales
Name          
David16$3008$600  19$10043$1,000
Jen        0$0
John10$100  2$2004$40016$700
Karen20$500      20$500
Tim        0$0
Total46$9008$6002$20023$50079$2,200
Patrick
Opal | Level 21

@mmaleta851 wrote:

Patrick_1-1673663117048.png

 

Hey Patrick, I want to get rid of the Missing data columns, but I want to keep the rows that have missing data to indicate which sales reps did not complete any sales in 2021.


 

Then below should work.

proc sql;
  create table work._classdata as
  select distinct
    name,
    max(date) as date format=YYQ8.
  from work.table
  ;
quit;

options missing=' ';
proc tabulate data=work.table classdata=work._classdata;
  where not (missing(date) and missing(sales));
  class Name Date;
  var Trips Sales;
  tables 
    Name All="Grand Total", 
    (Date="" ALL="Grand Total")*(Trips*(sum=''*f=6.0) Sales*(sum=''*f=DOLLAR12.));
run;

Patrick_0-1673693426915.png

 

mmaleta851
Fluorite | Level 6

Awesome! That does work. Can you explain what you did?

Patrick
Opal | Level 21

Secondary table _classdata contains all combinations of categories that you wanted in your report.

The where clause subsets the primary table to only the rows you actually want to include in your report.

 

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1hpbwr9acrbmen1e2d6hxjkotm1.htm 

Patrick_1-1673916872622.png

 

Example 2: Specifying Class Variable Combinations to Appear in a Table

 

 


https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n1hpbwr9acrbmen1e2d6hxjkotm1.htm#n1k7... 

 

 

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
  • 8 replies
  • 961 views
  • 2 likes
  • 2 in conversation