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-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
  • 1 reply
  • 814 views
  • 0 likes
  • 2 in conversation