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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 393 views
  • 4 likes
  • 3 in conversation