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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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