BookmarkSubscribeRSS Feed
jcooper3
Calcite | Level 5

Hi all-

I have the following dataset:

patient ID            quarter    CHF (and so on...there are ~23 more column variables then- all binary 0/1, with 1=yes the person has the condition)

3                            14          0

3                            16          0

3                            20          1

3                            23           0

...and so on

I want each patient to show 36 quarters (so 1-36) regardless of if they have the condition or not. Right now, the quarters that are showing up are only the ones that people have a "yes" for the condition in.

Does anytone know how I would add in the quarters that are missing. It is different w/ each patient.

Thanks!

1 REPLY 1
ballardw
Super User

Something like:

data temp;

     set have;

     by PatientId notsorted; /* if data is sorted by PatientId don't need the notsorted but assumes all the records for PatientId are together*/
     if first.PatientId then do quarter = 1 to 36;

          output;

     end;

run;

proc sql;

       create table want as

     select a.*, b.*

     from temp as a left join have as b on

          a.PatientId = b.PatientId;

quit;

You'll get a warning about PatientId and quarter being in both tables but b.* is shorter than listing all the variables in Have except PatientId and quarter.

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!

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
  • 1 reply
  • 308 views
  • 0 likes
  • 2 in conversation