BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bkq32
Quartz | Level 8
data have;
input tract_or_block tract $4. tract_per_white tract_per_black tract_per_hisp ses;
cards;
100 100 0.67 0.1 0.2 1.8
1001 100 . . . 1.5
1002 100 . . . 1.4
200 200 0.2 0.2 0.2 1.1
2001 200 . . . 1.2
2002 200 . . . 1.3
;
run;

I'm trying fill the missing values with the non-missing values by TRACT without getting rid of any rows or columns. I've tried the following code but can't figure out how to keep all the variables and records.

 

proc means data=have noprint nway;
 class TRACT
 var tract_per:;
 output out=want (drop= _TYPE_ _FREQ_) max= ;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @bkq32   Your input data structure looks like a classic sample for LOCF logic as opposed to summary and merge.Am i right in my understanding?If yes,

 


data have;
input tract_or_block tract $4. tract_per_white tract_per_black tract_per_hisp ses;
cards;
100 100 0.67 0.1 0.2 1.8
1001 100 . . . 1.5
1002 100 . . . 1.4
200 200 0.2 0.2 0.2 1.1
2001 200 . . . 1.2
2002 200 . . . 1.3
;
run;


data want;
update have(obs=0) have;
by tract;
output;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @bkq32   Your input data structure looks like a classic sample for LOCF logic as opposed to summary and merge.Am i right in my understanding?If yes,

 


data have;
input tract_or_block tract $4. tract_per_white tract_per_black tract_per_hisp ses;
cards;
100 100 0.67 0.1 0.2 1.8
1001 100 . . . 1.5
1002 100 . . . 1.4
200 200 0.2 0.2 0.2 1.1
2001 200 . . . 1.2
2002 200 . . . 1.3
;
run;


data want;
update have(obs=0) have;
by tract;
output;
run;
bkq32
Quartz | Level 8

Yes, this worked great. Thanks!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 632 views
  • 0 likes
  • 2 in conversation