DATA Step, Macro, Functions and more

How to impute the first observation value in the entire row

Reply
Contributor
Posts: 63

How to impute the first observation value in the entire row

How to impute the first observation value in the entire row

Trusted Advisor
Posts: 1,137

Re: How to impute the first observation value in the entire row

Posted in reply to venkatard

Hi,

An example with an output you desire to get will helps us to provide a proper code.

Thanks,

Jagadish

Thanks,
Jag
Trusted Advisor
Posts: 1,137

Re: How to impute the first observation value in the entire row

Posted in reply to Jagadishkatam

Hi,

Just thought to inform you that, for your query if you consider that you have a data as below and you want the first row values to be replaced with 0.

                            Obs    letter    num1    num2    num3    num4

                             1       a        100       1     101    1111

                             2       b         20     222       .       .

                             3       c         33       .       .       .

                             4       d        444      40       .       .

                             5       e          .       .       .       .

                             6       f          .       .       .       .

                             7       g          .       .       .       .

                             8       h         88       .       .       .

Here is the code that will produce the output you desire to get

data have;

  set final;

  array mis(4) num1-num4;

  do i = 1 to 4;

  if _n_=1 then mis(i)=0;

  end;

run;

                          Obs    letter    num1    num2    num3    num4    i

                           1       a          0       0      0       0     5

                           2       b         20     222      .       .     5

                           3       c         33       .      .       .     5

                           4       d        444      40      .       .     5

                           5       e          .       .      .       .     5

                           6       f          .       .      .       .     5

                           7       g          .       .      .       .     5

                           8       h         88       .      .       .     5

See the first row column values are replaced with 0. Hope this helps you.

Thanks,

Jagadish

Thanks,
Jag
Frequent Contributor
Posts: 97

Re: How to impute the first observation value in the entire row

Posted in reply to Jagadishkatam

hi,

i made some modifications to jagadish help,

      .....'If you want particlulary the first......observation to be imputed to entire row'' the follwing will helps you..

Note :  if first obs is  'Numeric' ...then only this would helps...

data ddd;
input first num1 num2;
datalines;
12 33 56
23 44 67
22 56 78
;
run;


data want(drop =i);
set ddd;
array mis(2) num1-num2;
do i = 1 to 2;

mis(i)=first;

end;
run;

Regards

ALLU

Ask a Question
Discussion stats
  • 3 replies
  • 229 views
  • 0 likes
  • 3 in conversation