While it is possible to create if→then actions that can be told not to include empty variables, in this case, I think the simpler solution would be to search and replace your text after inputting your values to get rid of all the empty lines. Feel free to copy the search-and-replace action used in this sample macro if you find it works for you, and please note that you will need to set your assembled variable values to a new variable or the clipboard (and use the appropriate search-and-replace action depending on which one you go with) before pasting them to make use of this solution.
Sample "Empty Variables" Macro.kmmacros (2.5 KB)
Results: