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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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