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

I have 2 datsets one with s_D_1, s_D_2, s_D_3, s_D_4, s_F_1, s_F_2, s_F_3, s_F_4 and the other dataset has variables n_D and n_F

I need to merge them and calculate precentages with 

= 100*(s/n). for both D and F.

 

Can any one help me in this

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your life would be much easier if you normalised your data, i.e. have something like:

S_D  RESULT

1      abc

2      def

...

Further processing of the data would be easier, and this task would be a simple merge and one calculation step.  With your transposed dataset, you will need to use arrays, and the code thus becomes a bit more complicated - not to mention further coding will be harder.  As you have not provided test data (in the form of a datastep) this code is untested:

data want;
  merge base other;  /* Assumes both are sorted by the id variables */
  by <id variables>;  /* update this row with the matching variables in each dataset */
  array s_d_{4};
  array s_f_{4};
  array s_d_results{4};
  array s_f_results{4};
  do i=1 to 4;
    s_d_results{i}=(s_d_{i} / n_d) * 100;
    s_f_results{i}=(s_f_{i} / n_f) * 100;
  end;
run;
 

Again though, far easier to normalise your data.

 

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Your life would be much easier if you normalised your data, i.e. have something like:

S_D  RESULT

1      abc

2      def

...

Further processing of the data would be easier, and this task would be a simple merge and one calculation step.  With your transposed dataset, you will need to use arrays, and the code thus becomes a bit more complicated - not to mention further coding will be harder.  As you have not provided test data (in the form of a datastep) this code is untested:

data want;
  merge base other;  /* Assumes both are sorted by the id variables */
  by <id variables>;  /* update this row with the matching variables in each dataset */
  array s_d_{4};
  array s_f_{4};
  array s_d_results{4};
  array s_f_results{4};
  do i=1 to 4;
    s_d_results{i}=(s_d_{i} / n_d) * 100;
    s_f_results{i}=(s_f_{i} / n_f) * 100;
  end;
run;
 

Again though, far easier to normalise your data.

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 1 reply
  • 1207 views
  • 0 likes
  • 2 in conversation