10-13-2017 01:54 PM - edited 10-13-2017 01:56 PM
I want to do a frequency on a variable using proc sql.
I am doint count(VariableName) and also group by (VariableName) but it does not count the records where there is no value.
I am looking for something equivalent to the missing option in proc freq.
Here is my code:
data have; input id Gender $; datalines; 1 M 2 F 3 M 4 . 5 . 6 F ; run; proc sql;
,count(Gender) as frequency
group by Gender
The output is:
I want the output to be like:
10-13-2017 02:09 PM
I was able to get this done but I am sure there is a better way to do it: Please suggest
proc sql; create table freq as select Gender ,sum(freq1,freq2) as frequency from ( select Gender ,nmiss(gender) as freq1 ,count(Gender) as freq2 from have group by Gender ) ;quit;
10-13-2017 02:23 PM
There is a valid reason to not use PROC FREQ -- maybe -- and that's if your data is in a database and you want the SQL work to push down to the database instead of bringing the data records into SAS.
However, that's not as true as it once was. PROC FREQ can push work down to the database in SAS 9.3 and later, as long as you're using a SAS/ACCESS library engine to get to it.
10-13-2017 03:28 PM
Change it to PROC FREQ.
Change it to count everything, not just Gender.
In the future post your code in a legible format, the post above requires edits which is a pain.
proc sql;select Gender,count(Gender) as frequencyfrom havegroup by Gender;quit;