BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
nwang5
Obsidian | Level 7

I have several missing values of alcohol. If the previous wave answered "never," the missing value would be
"never." If wave1 had a missing value and wave 2 had a non-missing value, the wave2's answer could be assigned to wave1. I was wondering if there is any way I can do that. Thanks!

Obsidwavefollow_up_yearalcoholExpected-alcohol
1100039114nevernever
2100039214nevernever
3100039314nevernever
4100039414nevernever
5100039514.never
6100039614nevernever
7100039714nevernever
8100039814nevernever
910004414nevernever
1010004424nevernever
11100052114.>=3
12100052214>=3>=3
13100052314.>=3
14100052414.>=3
15100052514.>=3
16100052614>=3>=3
17100052714.>=3
18100052814>=3>=3
19100055112>=3>=3
201000552121-21-2
211000553121-21-2
22100055412>=3>=3
23100055512.>=3
24100055612>=3>=3
25100055712.>=3
26100057114nevernever
27100057214nevernever
28100057314nevernever
29100057414nevernever
301000575141-21-2
31100057614.1-2
32100057714nevernever
331000578141-21-2
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data want;
/* first loop catches the first non-missing value */
do until (last.id);
  set have;
  by id;
  if _alcohol = "" then _alcohol = alcohol;
end;
do until (last.id);
  set have;
  by id;
  if alcohol = ""
  then alcohol = _alcohol;
  else _alcohol = alcohol;
  output;
end;
drop _alcohol;
run;

Untested, posted from my tablet.

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
data want;
/* first loop catches the first non-missing value */
do until (last.id);
  set have;
  by id;
  if _alcohol = "" then _alcohol = alcohol;
end;
do until (last.id);
  set have;
  by id;
  if alcohol = ""
  then alcohol = _alcohol;
  else _alcohol = alcohol;
  output;
end;
drop _alcohol;
run;

Untested, posted from my tablet.

Shmuel
Garnet | Level 18

Calrifications are needed:

1) You asked for * If the previous wave answered "never," the missing value would be
"never."  *. If the previous is non-missing and not "never" should it be copied to the current ?

2) How to act if 1st and 2nd (or more in sequence) are missing - should they get the first non-missing value or remain as they are ?

3) If ther are more than one missing value in sequence, should the value that was copied to the first one should be copied to the all following missing values ? (obs 13 gets value of obs 12. should it be copied to obs 14 and 15 too ?)

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 347 views
  • 1 like
  • 3 in conversation