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.
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
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.
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;
Data have;
input RelatedPartyTel_Number_Cell $;
0214675442
0110767466
0005678653;
run;
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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.