BookmarkSubscribeRSS Feed
Starsagitarian
Calcite | Level 5

Hello all,

My name is Baiju Joseph and I am a student.

I encountered a problem while doing a project, which I would like to share with you all

for a variable Base in a dataset following was the pattern:

Base
9
6
6
.
.
.
.
.
.
6
6
3
3
.
.
.
.
7
9
3

Now for all the null values I would like to put the preceding non zero value in it till I reach the next non zero value in the variable and so on and so forth, until there are no null values in the variable. for example Observations 4-9 are null, and hence I would like to fill in the value of the preceding non zero observation (ie Obs 3 with value 6) in all the observations till I reach Obs 10, which is a non zero observation.

what can be done to achieve this ??

Kindly reply back with your answers

Thank you all !!!

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

There are several ways to do this, first one that springs to mind for me is a retain:

data want;

     set have;

     retain lstval;

     if base ne . then lstval=base;

     else base=lstval;

run;

There are other suggestions if you search the forums.

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