DATA Step, Macro, Functions and more

Proc SQL display all categories

Reply
Contributor
Posts: 50

Proc SQL display all categories

Hi All,

 

My code:

PROC SQL;
 SELECT programtypeid, COUNT(childid) AS NewEnroll_ByCou_YTD
  FROM counts
  where '01jan2016'd <= dateeval <= &tdate
  group by programtypeid;
QUIT;

Gives me this output:

SAS Output

Neighborhoods NewEnroll_ByCou_YTD
Central Bronx2
Bronx Park and Fordham3
High Bridge and Morrisania4
Hunts Point and Mott Haven2
Central Harlem10
Chelsea and Clinton1
East Harlem42

 The Neighborhoods variable has 35 more categories and I would like them all listed, even if they are all zeros. Is there a way to do this?

 

Thanks!

PROC Star
Posts: 1,558

Re: Proc SQL display all categories

The 35 neighborhoods are not in the SAS table or they would have appeared.

Unless you mean that are there but with other dates?

In which case something like this may do:

 

PROC SQL;
   SELECT programtypeid, sum(   '01jan2016'd <= dateeval <= &tdate )   AS NewEnroll_ByCou_YTD
   FROM counts
   group by programtypeid;
QUIT;
Occasional Contributor
Posts: 8

Re: Proc SQL display all categories

[ Edited ]

Maybe the categories that they don't satify the condition they aren't listed.

 

I'm going to write another possibility.

PROC MEANS DATA=COUNTS NMISS N;
ID programtypeid;
VAR childid;
OUTPUT OUT=SALIDA(N=NewEnroll_ByCou_YTD); RUN;
PROC SORT DATA=SALIDA;
BY PROGRAMTYPEID;
RUN;

 You should include your condition with WHERE;

Contributor
Posts: 33

Re: Proc SQL display all categories

Do you have a format to transform programtypeid to Neighborhoods?

 

Untested, assuming that a format exists and is named $Neighborhoods:

proc summary data=counts(where=('01jan2016'd <= dateeval <= &tdate)) completetypes nway;
  class programtypeid / preloadfmt order=data;
  format programmtypeid $Neighborhoods.;
  output out=work.CountComplete(drop=_type_ rename=(_freq_=NewEnroll_ByCou_YTD));
run;

proc print data=work.CountComplete noobs;
run;
Ask a Question
Discussion stats
  • 3 replies
  • 216 views
  • 1 like
  • 4 in conversation