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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.