BookmarkSubscribeRSS Feed
cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

Hello,

I have data like below with different Item values  

Item    status_x        status_y          status_z

05     completed      cancelled        completed

05     cancelled                               completed

05     cancelled       completed

05     completed

05     completed      completed       completed

05                           cancelled         completed

05      cancelled      completed       completed

08                           completed

 - - - -  - - - - - -

10                           cancelled       completed

- - -  - - - - - -  - - - -

I need counts of any one status completed, any two status completed and all 3 status completed by Item, like below table

Item    1statuscompleted  2statuscompleted   3statuscompleted nostatuscompleted

05                  4                           2                                  1                       0

08          ----  

10          -----

 

Appreciate your help.

TIA

3 REPLIES 3
Reeza
Super User
I would do a PROC TRANSPOSE on your input table and then likely a PROC FREQ to get the summaries you want. Does it need to be dynamic or do you only need to consider 3 statuses at a time?
Shmuel
Garnet | Level 18

Some clarification needed:

1) Is 1statuscompleted   show the frequency of COMPLETED in status_x ?

    or the first value of the item (excluding missing values), as in next example:

Item    status_x        status_y          status_z
08                      completed

2) Is nostatuscompleted frequency of CANCELED only or including missing values?

3) Do you need the output as a report or as a dataset?

 

Please check next code:

data temp;
 set have;
     array stat {3} $ status_x status_y status_z;
	 array frq {4} frq1-frq4;
	 do i=1 to dim(stat);
	    if stat(i) = 'completed' then j=i;
		else if not missing(stat(i)) then j=4;
		else j=0;
		if j then frq(j) = 1;
	 end;
	 keep item frq1-frq4;
run;
proc summary data=temp noprint nway;
     class item;
	 var frq1-frq4;
	 output out=want(drop _type_ _freq_) sum=;
run;
proc print data=want;
     var item frq1-frq4;
	 label
	    frq1 = "1statuscompleted"
		frq2 = "2statuscompleted"
		frq3 = "3statuscompleted"
		frq4 = "nostatuscompleted"
	 ;
run;

 

cm3
Fluorite | Level 6 cm3
Fluorite | Level 6

thanks for your help

1)any one of the Status value should be "completed"

other two status values could be "cancelled" or blank

2)none of the 3 status variables should have "completed"

3)need out put data set 

 

Thanks again

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
  • 3 replies
  • 566 views
  • 0 likes
  • 3 in conversation