substitute a line in a file if line number is available

Hi guys,
is there are way to substitute the content of certain line in the file by another entry if line number is available?
For example, I have a variable A="HCMLPBBG" and a file MYFILE.
I need to substitute entry on line 18168 of MYFILE with the value of the variable "A".
Is there a way to do it?
Thanks a lot for advice.

awk -v LINE=18168 -v A="$A" '{ if(NR==LINE) $0=A; } 1' < infile > outfile
cat outfile >infile
rm -f outfile