BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
thenewlearner
Calcite | Level 5

Hi everyone,

 

New learner on SAS, now onto the array. doing practice from the base certification disc on chapter 16. Here's a question about array:

 

the following codes seem to extract just the numeric values in the original data set and do calculations (staff donation * 1.25 = company+staff= total contribution), i want to do some adjustments so i can show: 1. staff contribution (the original value), company contribution (original *0.25) and the total ( 1.25);

 

not quite sure how i can array it and show them all in one table.

 

this is the practice code:

 

data sasuser.added(drop=i);
   set sasuser.funddrive;
   array contrib{4} qtr1-qtr4;
   do i=1 to 4;
      contrib{i}=contrib{i}*1.25;
   end;
run;
proc print data=sasuser.added;
run;

 

Thank you all.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You can use the array statement to create new variables:

data sasuser.added(drop=i);
set sasuser.funddrive;
array contrib{4} qtr1-qtr4;
array comp_contrib{4} c_qtr1-c_qtr4;
do i=1 to 4;
  comp_contrib{i} = contrib{i} * 0.25;
end;
run;

I leave it to you how you add the third array and do the calculation for that.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

You can use the array statement to create new variables:

data sasuser.added(drop=i);
set sasuser.funddrive;
array contrib{4} qtr1-qtr4;
array comp_contrib{4} c_qtr1-c_qtr4;
do i=1 to 4;
  comp_contrib{i} = contrib{i} * 0.25;
end;
run;

I leave it to you how you add the third array and do the calculation for that.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not quite following, but at a guess I would say you just need to further arrays:

data sasuser.added (drop=i);
   set sasuser.funddrive;
   array contrib{4} qtr1-qtr4;
array staff_contrib{4};
array comp_contrib{4};
array total{4}; do i=1 to 4; contrib{i}=contrib{i}*1.25;
staff_contrib{i}=contrib{i};
comp_contrib{i}=contrib{i}*0.25;
total{i}=1.25; end; run;
thenewlearner
Calcite | Level 5

Thanks Kurt and RW9.

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
  • 3 replies
  • 1186 views
  • 0 likes
  • 3 in conversation