BookmarkSubscribeRSS Feed
aidant01
Fluorite | Level 6

Hi, 

 

I currently have table with vaccination date for each type of vaccination administered to a patient, where each row is a patient. A_date1 is the vaccination date of the first dose of vaccine A. I want a table with three additional columns totaling the doses given for each vaccination (a_total, b_total,c_total). There are a total of 9 vaccinations with a vaccination having up to 5 doses.

 

I had tried:

Array Raw {*} item1-item9; Array Key {9} $ _temporary_

(‘A’ ‘B’ ‘C’ ‘D’ ‘E’ 'F' 'G' 'H' 'I'); Array Score {9} ;

Do i = 1 to 9;
if raw{i} eq key{i} then total{i}=1; else total{i}=0;

End;
TotalCorrect = sum( of total1 – total9 );

 

I have:

a_date1a_date2a_date3b_date1b_date2b_date3b_date4b_date5c_date1c_date2c_date3c_date4c_date5
1/2/012/10/01 2/1/014/2/017/15/018/1/0110/1/011/1/20012/1/20014/20/018/22/01

9/15/01

 

I want:

a_date1a_date2a_date3b_date1b_date2b_date3b_date4b_date5c_date1c_date2c_date3c_date4c_date5a_totalb_totalc_total
1/2/012/10/01 2/1/014/2/017/15/018/1/0110/1/011/1/20012/1/20014/20/018/22/019/15/01255

 

 

 

 

 

6 REPLIES 6
PaigeMiller
Diamond | Level 26
data want;
     set have;
     a_total=n(of a_:);
     b_total=n(of b_:);
/* I'm lazy, you type the c_total formula */
run;

 

No arrays needed. Assumes the values of a_date1 and the rest of the dates are numeric.

 

Hint: better to describe the problem and leave out of the description that you want to use a specific tool in SAS (in this case, arrays).

--
Paige Miller
Reeza
Super User
Do you have naming conventions as shown in your post?

The counts are based on the number of dates filled in, eg. 2 is count of a_date1 and a_date2?

Are your variables SAS dates (numeric with a date format) or character?
aidant01
Fluorite | Level 6
Yes, counts are based on the number of dates filled in. And the variables are SAS dates.
PaigeMiller
Diamond | Level 26

@aidant01 wrote:
Yes, counts are based on the number of dates filled in. And the variables are SAS dates.

Hello, @aidant01 please clarify. I assume the above means that the date variables are numeric, but you didn't actually say that, so I would like clarification.

--
Paige Miller
aidant01
Fluorite | Level 6

Yes, the date variables are numeric in SAS date format. a_count, b_count, c_count would be numeric integers.

Reeza
Super User
Paige's solution will work then, as long as you have some sort of naming conventions with prefixes.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 733 views
  • 4 likes
  • 3 in conversation