New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bgosiker
Obsidian | Level 7

 

Hi everyone, 

 

I have a long dataset and some missingness in my data. For places where there are some gaps in data I was wanting to carry forward the most recent value a maximum of TWO times. I have this code that carries forward the value of smokestat until the next non-missing value of smokestat, but I don't want it to carry it forward that far. I was having some issues adapting this code to only carry it forward a maximum of two visits. Any help appreciated!

data Aim2.Final; set Aim2.Final;
	 n=_n_;
	 if missing(smokestat) then do;
	   do until (not missing(smokestat));
	     n=n-1;
	     set Aim2.Final(keep=smokestat) point=n;  
	   end;
	 end;
run;

Hi everyone, 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

A reasonable approach:

 

data want;
   set have;
   retain n replacement;
   if smokestat > . then do;
      replacement = smokestat;
      n = 0;
   end;
   else do;
      n + 1;
      smokestat = replacement;
      if n = 2 then call missing(replacement);
   end;
run;

View solution in original post

1 REPLY 1
Astounding
PROC Star

A reasonable approach:

 

data want;
   set have;
   retain n replacement;
   if smokestat > . then do;
      replacement = smokestat;
      n = 0;
   end;
   else do;
      n + 1;
      smokestat = replacement;
      if n = 2 then call missing(replacement);
   end;
run;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1 reply
  • 1945 views
  • 1 like
  • 2 in conversation