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

Hi all,

I have a macro that runs each ID in a group through a series of tests.  One of the result tables of the test is a 5-row, 2-column table that shows the result of the test and the number of observations in this particular ID that meet each possible result.  The table looks like this:

Result    Count

A           15

B           2

C           33

D           45

E           11

All works fine when I try this on the bigger IDs, which have all five groups, but when I run it on the smaller IDs which may only have some of the results, I'm having trouble consistently outputting the same result.  Ultimately, what I'd like to do is have the above table populated all the time with all five rows and have a zero value populated in the case that any given result has no observations:

What I want:

Result    Count

A           15

B           0

C           33

D           45

E           11

What I'm getting:

Result    Count

A           15

C           33

D           45

E           11

This is a common problem that I run into that I haven't quite figured out how to do consistently.  I'm sure there are some pretty standard techniques to build a table template like what I'm looking for and then using some sort of conditional logic (or another approach) to fill in even when all five results aren't present.

Thanks!    

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

You can make a dataset temp like:

A

B

C

D

E

Then use code:

data want;

merge temp yourdataset;

by ...

run;

Ksharp

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

You didn't show your current code, thus one can only guess.  Two possibilities are using the sparse option in proc freq or the preloadfmt option in a number of procs.  Take a look at:

http://www.nesug.org/proceedings/nesug02/cc/cc003.pdf

HTH,

Art

Ksharp
Super User

You can make a dataset temp like:

A

B

C

D

E

Then use code:

data want;

merge temp yourdataset;

by ...

run;

Ksharp

AvocadoRivalry
Calcite | Level 5

Thanks Ksharp - that was exactly the answer I needed!  Nice and simple.    

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1997 views
  • 1 like
  • 3 in conversation