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

Hi,

Could someone help me with MTD % how can I get this based on organisation A, B, C wise and status C for complete and P for pending.

data test;
input Date :Date9. Year Month $ Org $ Status $;
format Date date9.;
datalines;
07Dec2022 2022 Dec A C
14Jan2023 2023 Jan A C
02Feb2023 2023 Feb A C
02Feb2023 2023 Feb A P
03Feb2023 2023 Feb B C
21Feb2023 2023 Feb C C
24Feb2023 2023 Feb C C
27Feb2023 2023 Feb C P
;
run;

Expected output: From above data org A in Feb is having 1 complete and 1 pending so my % completion should be 50% each, similarly org C in Feb total 3 out of which 2 is completed and 1 is pending.

vnreddy_0-1691153266922.png

 

Thanks

Vennapusa

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
PROC Star

@vnreddy wrote:

Hi @Quentin apart from tabular is there any other way of getting it in list table.

I need to join this table to an another table.


Yes, TABULATE has an out= option that will write an output dataset.

 

proc tabulate data=test order=data missing out=want;
  class Year Month Org Status ;
  tables Year*Month*Org*Status,pctn<Status>='Per_comp' ;
run ;

proc print data=want ;
run ;

 

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

I am not sure what MTD % is. I also request you explain how the column PER_COMP is computed from the original data, as I'm not sure I understand what you want.

--
Paige Miller
vnreddy
Quartz | Level 8

Hi @PaigeMiller 

I am trying to calculate the % of C & P on a monthly basis. 

 

PaigeMiller
Diamond | Level 26

@vnreddy wrote:

Hi @PaigeMiller 

I am trying to calculate the % of C & P on a monthly basis. 

 


Please avoid speaking in abbreviations, as I also don't understand C&P in this context. Please provide actual information that I requested, specifically "I also request you explain how the column PER_COMP is computed from the original data". Please don't ignore this request.

--
Paige Miller
vnreddy
Quartz | Level 8

@PaigeMiller Status column C stands for Complete and P for Pending.

I am trying the Per_comp which is the % breakdown based on Complete and Pending status by Org and Month basis.  As you can see e.g., Org C in the month of Feb has 3 total rows out of which 2 is with (complete) C status and 1 is (Pending) P status. Number of (complete) C status/total rows in Feb based on Org C, Number of (pending) P status/total rows in Feb based on Org C which is  66.37% & 33.33%

Quentin
PROC Star

Can you show the code you have tried?  It looks like you could get the answer with PROC FREQ, or maybe a prettier table with PROC TABULATE.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
Kurt_Bremser
Super User
data test;
input Date :Date9. Year Month $ Org $ Status $;
format Date date9.;
yymm = input(cats(month,year),monyy7.);
format yymm yymmn6.;
datalines;
07Dec2022 2022 Dec A C
14Jan2023 2023 Jan A C
02Feb2023 2023 Feb A C
02Feb2023 2023 Feb A P
03Feb2023 2023 Feb B C
21Feb2023 2023 Feb C C
24Feb2023 2023 Feb C C
27Feb2023 2023 Feb C P
;

data want;
set test;
by org yymm;
if first.yymm
then do;
  comp = 0;
  n = 1;
end;
else n + 1;
comp + (status = "C");
if last.yymm;
mtd = comp / n;
format mtd percent7.2;
keep org yymm mtd;
run;
vnreddy
Quartz | Level 8

Hi @Kurt_Bremser 

As per your logic i am getting below results.

vnreddy_1-1691157150661.png

 

I want to see both (complete) C and (Pending) P status for e.g., from source data for Org A in Feb we have total 2 rows out of which 1 is complete and 1 is pending.

Quentin
PROC Star

Assuming you want a report, I would play with PROC TABULATE.  Something like:

 

proc tabulate data=test order=data missing;
  class Year Month Org Status ;
  tables Year*Month*Org*Status,pctn<Status>='Per_comp' ;
run ;

Returns:

Tabulate.PNG

 

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
vnreddy
Quartz | Level 8

Hi @Quentin apart from tabular is there any other way of getting it in list table.

I need to join this table to an another table.

Quentin
PROC Star

@vnreddy wrote:

Hi @Quentin apart from tabular is there any other way of getting it in list table.

I need to join this table to an another table.


Yes, TABULATE has an out= option that will write an output dataset.

 

proc tabulate data=test order=data missing out=want;
  class Year Month Org Status ;
  tables Year*Month*Org*Status,pctn<Status>='Per_comp' ;
run ;

proc print data=want ;
run ;

 

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 439 views
  • 4 likes
  • 4 in conversation