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

Hi all, hope you can help me.

 

I got a table with several columns and I want to make a sum based on each one without making a new column for each variable. (see attached table)

 

12,5%12,5%12,5%6,8%7,3%8,3%6,5% 
Illiteracyschool absenteeismschool backwardnessaqueduct_problemsSewerage_problemsFloorsWallsSum
   YES YESYES21,6%
 YESYESYESYES  39,1%
YES YESYES  YES38,3%

 

I want to get the sum of the row according to the weight assigned and the value of the field (e.g. in the first row we add aqueduct_problems, Floors and Walls getting 21.6%)

 

is there a way to do it?  many thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Only you know what those values are, but it's certainly possible to modify just one line of the program, something like:

 

if reasons{_n_} in ('YES' 'MAYBE') then ....

View solution in original post

3 REPLIES 3
Astounding
PROC Star

One possible approach would use arrays.  Assuming that I'm spelling your variable names correctly:

 

data want;

set have;

array reasons {7} illiteracy school_absenteeism school_backwardness aqueduct_problems sewerage_problems floors walls;

array weights {7} _temporary_ (0.125 0.125 0.125 0.068 0.073 0.083 0.065);

sum=0;

do _n_=1 to 7;

   if reasons{_n_} = 'YES' then sum + weights{_n_};

end;

run;

 

I left SUM as a decimal fraction.  You might want to apply a format to that for printing purposes.

antonioy2m
Calcite | Level 5
Many thanks for your answer Astounding, i didn't put the entire table but in some cases i have to add to the sum other values diferent to yes, do you know other solutión? thanks!
Astounding
PROC Star

Only you know what those values are, but it's certainly possible to modify just one line of the program, something like:

 

if reasons{_n_} in ('YES' 'MAYBE') then ....

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1016 views
  • 1 like
  • 2 in conversation