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_date1 | a_date2 | a_date3 | b_date1 | b_date2 | b_date3 | b_date4 | b_date5 | c_date1 | c_date2 | c_date3 | c_date4 | c_date5 |
1/2/01 | 2/10/01 | 2/1/01 | 4/2/01 | 7/15/01 | 8/1/01 | 10/1/01 | 1/1/2001 | 2/1/2001 | 4/20/01 | 8/22/01 | 9/15/01 |
I want:
a_date1 | a_date2 | a_date3 | b_date1 | b_date2 | b_date3 | b_date4 | b_date5 | c_date1 | c_date2 | c_date3 | c_date4 | c_date5 | a_total | b_total | c_total |
1/2/01 | 2/10/01 | 2/1/01 | 4/2/01 | 7/15/01 | 8/1/01 | 10/1/01 | 1/1/2001 | 2/1/2001 | 4/20/01 | 8/22/01 | 9/15/01 | 2 | 5 | 5 |
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).
Yes, the date variables are numeric in SAS date format. a_count, b_count, c_count would be numeric integers.
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!
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.
Ready to level-up your skills? Choose your own adventure.