BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mitrakos
Obsidian | Level 7

Hello!

I previously asked a similar question in this forum, and was met with a great answer, however this situation is a bit different...

 

I am trying to include missing weeks in my proc freq analysis with a count of 0, however there is a problem in that the weeks repeat. See below. 

IDdateCOUNT
120W072
120W081
120W091
220W083
220W091
320W053
320W062
320W081

 

I am looking at counts between a specific range of dates (20W05 - 20W09). I want the weeks that don't show up for each ID to show up as a count of 0. The complicated part is that the weeks repeat due to the ID's repeating. I suspect it may be some sort of "If and" statement, but I do'n't really know. Using MISSPRINT and MISSING haven't worked. Any ideas? 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Try PROC FREQ with the SPARSE option. That sounds like exactly what you are asking for.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=procstat&docsetTarget=pro...

--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Try PROC FREQ with the SPARSE option. That sounds like exactly what you are asking for.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=procstat&docsetTarget=pro...

--
Paige Miller
mitrakos
Obsidian | Level 7

Hello!

Unfortunately I am not sure that worked, I see no 0's in my output. Here is my code:

proc freq data=import;
where date >= '03FEB2020'd and date <='03MAR2020'd;
tables date / sparse out = freq;
format date weeku6.;
by pid;
run;
PaigeMiller
Diamond | Level 26

You don't want to put PID in the BY statement. You want

 

tables pid*date / sparse out = freq;
--
Paige Miller
mitrakos
Obsidian | Level 7
IT WORKED! Thank you so much!!!
Reeza
Super User
Did you want to count by ID?
It seems like your code is including ID in the PROC, if you don't want the counts per ID then remove the ID.
If the missing weeks is somewhere in the data set you can use the SPARSE option. If not, you need to use PRELOADFMT or CLASSDATA likely within PROC TABULATE instead of FREQ.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1327 views
  • 0 likes
  • 3 in conversation