BookmarkSubscribeRSS Feed
Mto
Calcite | Level 5 Mto
Calcite | Level 5

Hello,

 

Is it possible to fill in the missing values with the previous value, using SAS EG without editing the code manually?

 

a b

1 8

4 10

5 12

 

should be

a b

1 8

2 8

3 8

4 10

5 12

 

Thanks in advance!

7 REPLIES 7
Reeza
Super User

Not easily...the fastest way is to write a data step. 

Kurt_Bremser
Super User

This is beyond the scope of the wizards in EG.

 

Try

 

data want;
set have;
retain oldb;
if b = . then b = oldb;
oldb = b;
drop oldb;
run;

(asssuming that b is a numeric variable)

Mto
Calcite | Level 5 Mto
Calcite | Level 5

Thank you Kurt.

 

(As a 'noob') where can I insert this code?

And what if 'b' is not a numeric value?

 

Thanks in advance,

Maarten

Kurt_Bremser
Super User

The missing value for a string is the empty string, most often represented as '' or "" (single or double quotes with nothing or just blanks in between).

 

The code transforms the existing data set "have" into the new dataset "want", which is the typical generic nomenklatura for datasets in examples here.

Mto
Calcite | Level 5 Mto
Calcite | Level 5

Thank you very much, Kurt!

I will definitely follow your advice to learn more about data step and procedure coding 🙂

 

For now, can you help with the question where I should add the 'data-want' code?

 

 

Kurt_Bremser
Super User

As far as I can infer from the postings up to now, you somehow get a SAS dataset with missng values, which you want to have corrected.

Let's assume this dataset is found in your SAS environment as XXXX.YYYY (XXXX being a library, and YYYY being the dataset name).

You need to find the spot in your existing code (nothing in SAS is done without SAS code), and then you can add my code snippet. If you replace "have" and "want" with XXXX.YYYY, you get a step that rewrites the dataset "in place" with the corrected values.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 7 replies
  • 1238 views
  • 0 likes
  • 3 in conversation