BookmarkSubscribeRSS Feed
hwangnyc
Quartz | Level 8

Hi All,

 

My code:

 

 

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

Gives me the output below. However, there are 35 other cateorgies that are associated with this variable. Is there a way to have them all listed? So in total it would be 42 rows, All the neighborhoods listed and zeros?

 

 

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 Harlem

42

 

4 REPLIES 4
Reeza
Super User

Not within Proc SQL, easily. 

 

Look up PRELOADFMT and proc tabulate. You can also try proc freq with sparse option. 

gamotte
Rhodochrosite | Level 12

Hello,

 

With proc sql, maybe sometghing like this :

 

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

UNION

SELECT DISTINCT Neighborhoods, 0 AS  NewEnroll_ByCou_YTD
  FROM counts
WHERE dateeval<'01jan2016'd OR dateeval>&Marco_tdate;
QUIT;
ballardw
Super User

Not an elegant solution but create a base data set with the values for the variable and a count of 0.

Create a dataset from your counting code.

The create a report data set by updating the value in the base set from the counting set.

 

But for a report I would use @Reeza's Proc tabulate approach, especially if I'm doing this very often.

Ksharp
Super User
data levels;
sex='F';output;
sex='M';output;
sex='X';output;
run;

data class;
 set sashelp.class(in=ina) levels;
 w=ina;
run;

proc freq data=class;
table sex;
weight w/zeros;
run;
 

 

x.png

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 801 views
  • 0 likes
  • 5 in conversation