How to impute the first observation value in the entire row
Hi,
An example with an output you desire to get will helps us to provide a proper code.
Thanks,
Jagadish
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
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
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.
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.