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.    

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!

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.

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
  • 998 views
  • 1 like
  • 3 in conversation