How can i change variable if condition is not met

If the user does not exist then your template should return something to say that the user does not exist instead of attempting to echo out their data, example:

<?php $keyuser = get_user_by('login', $username); ?>
<?php if(empty($keyuser)): ?>
    <p>That username does not exist, please check for typos or try a different search cryteria.</p>
<?php else: ?>
    <table>
        <tr>
            <th>User ID</th>
            <th>Username</th>
            <th>Email Address</th>
            <th>Roles</th>
        </tr>
        <tr>
            <td><?php echo $keyuser->ID; ?></td>
            <td><?php echo $keyuser->user_login; ?></td>
            <td><?php echo $keyuser->user_email; ?></td>
            <td><?php echo $keyuser->roles[0]; ?></td>
        </tr>
    </table>
<?php endif; ?>

If this is not feasible and you need to set the variables to a blank string then you could use a ternary if statement if you think that looks neater / to reduce typing

$keyuser = get_user_by('login', $username);
$byusername_dename = $keyuser->user_login ?: '';
$byusername_deemail = $keyuser->user_email ?: '';
$byusername_hisrole = $keyuser->roles[0] ?: '';
$byusername_id = $keyuser->ID ?: '';