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

Hello

how do i calculate percentage of the below ,per field. using proc freq or proc sql

PROC SQL;
TITLE 'NPS_2022101';
CREATE TABLE DATA_QUALITY_202210 AS 
SELECT COUNT (*) AS COUNT 
	,	COUNT (CASE WHEN CELLPHONE_NO IS NULL THEN 1 END)AS BLANKS
	,	COUNT (CASE WHEN CELLPHONE_NO = '00' THEN 1 END) AS DOES_NOT_COMPLY
	,	COUNT (CASE WHEN CELLPHONE_NO ^= '00' AND CELLPHONE_NO ^= '' THEN 1 END) AS COMPLY_WITH_RULE

FROM VIEWS;
QUIT;

desired outcome.

Rixile106_1-1675347040360.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

If you can, in plain English, state the rules you want to use, these are easily turned into SAS code.

 

So in this case:

 

If RelatedPartyTel_Number_Cell is null then blank

if RelatedPartyTel_Number_Cell begins with '00' then does_not_comply

if RelatedPartyTel_Number_Cell does not begin with '00' and not blank then comply_with_rule

 

SAS CODE

 

data have2;
    set have;
    length type $ 15;
    if RelatedPartyTel_Number_Cell=' ' then type='Blank';
    else if RelatedPartyTel_Number_Cell=:'00' then type='Does Not Comply';
    else type='Comply With Rule';
run;

proc freq data=have2;
    tables type;
run;

 

 

 

The "begins with" in SAS data steps is the =: (equal followed by colon) operator

 

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Percents are easily calculated in PROC FREQ (assuming that the percents must add to 100%). If you can show us the original data, we could provide code.

--
Paige Miller
Rixile106
Fluorite | Level 6

as per your request see below.

 

PROC SQL;
CREATE TABLE VIEWS AS
select  SUBSTR ((RelatedPartyTel_Number_Cell),1,2) AS CELLPHONE_NO

FROM BCC.NPS_EXTRACT_2022101;

QUIT;

Rixile106
Fluorite | Level 6

Data have;

input RelatedPartyTel_Number_Cell $;

0214675442

0110767466

 

0005678653;

run;

 

 

PaigeMiller
Diamond | Level 26

If you can, in plain English, state the rules you want to use, these are easily turned into SAS code.

 

So in this case:

 

If RelatedPartyTel_Number_Cell is null then blank

if RelatedPartyTel_Number_Cell begins with '00' then does_not_comply

if RelatedPartyTel_Number_Cell does not begin with '00' and not blank then comply_with_rule

 

SAS CODE

 

data have2;
    set have;
    length type $ 15;
    if RelatedPartyTel_Number_Cell=' ' then type='Blank';
    else if RelatedPartyTel_Number_Cell=:'00' then type='Does Not Comply';
    else type='Comply With Rule';
run;

proc freq data=have2;
    tables type;
run;

 

 

 

The "begins with" in SAS data steps is the =: (equal followed by colon) operator

 

--
Paige Miller
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
  • 4 replies
  • 1466 views
  • 0 likes
  • 2 in conversation