Hi,
I have a variable, utilisation, which has a range of values. I have the following SAS code below to start but is there a line(s) that someone could help me with in order to create a table which counts the number of records where the variable utilisation=0, utilisation<0.65 and utilisation>0.65, so the output data looks like the table below and have the same headings? Thanks.
proc sql;
create table utilisation as
select
utilisation,
count(*)
from rc.accounts
group by 1;
quit ;
I wouldn't use PROC SQL for a problem like this. Use PROC FORMAT and PROC FREQ in combination like this
data somedata;
do x=1 to 1000;
utilisation=rand('uniform');
output;
end;
do x=1 to 100;
utilisation=0;
output;
end;
run;
proc format library=work;
value overunder
0 = '0'
0 <- .65 = '<= 0.65'
.65 <- high = '> 0.65'
other = 'Unknown';
run;
proc freq data=somedata;
tables utilisation / nocum nopercent out=want;
format utilisation overunder.;
run;
In this scenario, should the zero values also be counted as under .65 or are they mutually exclusive? 🙂
Ok. So what about negative values? 🙂
Ok. Please see if the below code works for you 🙂
I wouldn't use PROC SQL for a problem like this. Use PROC FORMAT and PROC FREQ in combination like this
data somedata;
do x=1 to 1000;
utilisation=rand('uniform');
output;
end;
do x=1 to 100;
utilisation=0;
output;
end;
run;
proc format library=work;
value overunder
0 = '0'
0 <- .65 = '<= 0.65'
.65 <- high = '> 0.65'
other = 'Unknown';
run;
proc freq data=somedata;
tables utilisation / nocum nopercent out=want;
format utilisation overunder.;
run;
Always good to double check. But no, no need to add an equal sign 🙂
This
0 <- .65
does not include 0, but does include 0.65
This
0 - .65
includes both values and this
0 <-< .65
includes neither 🙂
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.