BookmarkSubscribeRSS Feed
uabcms
Calcite | Level 5
I have a large excel file for which I need to fill in missing data for a by-group
variable. It has a value of the by-variable for the first observation in
each by-group but the remaining observations are missing the
by-variable . I would like to occupy that field. Also, the file may not have
the same number of observations within each by-group.
1 REPLY 1
deleted_user
Not applicable
assuming you have already loaded data from excel, just add this small unit of code[pre]
* after "by" group columns loaded ;
retain _ret_by1 ;
if not missing( &by_var1 ) then _ret_by1 = &by_var1 ;
else &by_var1 = ret_by1 ;
retain _ret_by2 ;
if not missing( &by_var2 ) then _ret_by2 = &by_var2 ;
else &by_var2 = _ret_by2 ;
.... etc ....
drop _ret_: ;
[/pre]
I've streamlined the code so you can extend it for as many by-vars as you need. Just remember to establish the macro vars with the names of the BY-vars to be "retained". The code above should work in SAS9 whatever data-types the BY-vars have.

hope this helps !

PeterC

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1018 views
  • 0 likes
  • 2 in conversation