BookmarkSubscribeRSS Feed
altijani
Quartz | Level 8

Hello 

I need to use the below data to count the number of non-missing IDs. The goal is to reach the percentage completion for each region:

LocationStoreCase_ID
EastACase1
EastACase1
WestB.
SouthXCase2
SouthX.
SouthYCase3
SouthYCase3
SouthZCase4
WestACase5

 

Requested results:

LocationNumber UNIQUE StoresNon-Missing IDs for these stores% completion IDs
East11100%
West2150%
South33100%

 

Thank you everyone.

6 REPLIES 6
Angel_Larrion
SAS Employee

You can obtain that with a proc sql:

 

proc sql;
create table want as select Location, count(distinct Store) as unique_stores, count(distinct Case_ID) as not_missing_id, count(distinct Case_ID)/count(distinct Store) as cmplt_id format=percent7. from have group by Location; quit;

 

 

Angel_Larrion
SAS Employee
The count function ignores missing values, and the distinct option counts unique values.
altijani
Quartz | Level 8

Hi. Thanks, but this code does not provide the results I am looking for. It provides instead this results as 1, 1, 1 

 

I am looking for

1. the total number of stores in each region

2. For those stores, how many of them have completed (non missing) IDs?

Angel_Larrion
SAS Employee

i ran that code and this is the output table

 

Angel_Larrion_0-1611949407165.png

 

in the Case_id column do you have dots or missing values (i.e. space blank)?

altijani
Quartz | Level 8

Yes. Many.

Angel_Larrion
SAS Employee

could you try this code and share the output:

 

data have;
set have;
if case_id="." then case_id="";
run;

proc sql;create table want as
select Location, 
	   count(distinct Store) as unique_stores,
	   count(distinct Case_ID) as not_missing_id, 
	   count(distinct Case_ID)/count(distinct Store) as cmplt_id format=percent7.
from have
group by Location;
quit;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 1177 views
  • 0 likes
  • 2 in conversation