BookmarkSubscribeRSS Feed
hwangnyc
Quartz | Level 8

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!

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

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;
toconero
Fluorite | Level 6

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;

error_prone
Barite | Level 11

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 904 views
  • 1 like
  • 4 in conversation