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-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
  • 6 replies
  • 567 views
  • 0 likes
  • 2 in conversation