BookmarkSubscribeRSS Feed
venkatard
Calcite | Level 5

How to impute the first observation value in the entire row

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Hi,

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

Thanks,

Jagadish

Thanks,
Jag
Jagadishkatam
Amethyst | Level 16

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
allurai0412
Fluorite | Level 6

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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