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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 929 views
  • 0 likes
  • 2 in conversation