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!
You can make a dataset temp like:
A
B
C
D
E
Then use code:
data want;
merge temp yourdataset;
by ...
run;
Ksharp
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
You can make a dataset temp like:
A
B
C
D
E
Then use code:
data want;
merge temp yourdataset;
by ...
run;
Ksharp
Thanks Ksharp - that was exactly the answer I needed! Nice and simple.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.