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

hello,

 

I have a large data set, look like this :

 

data mydata;
input id month mark last;
cards;
1 4 14.5 28
1 1 . .
1 3 . .
2 7 . .
;
run;

 

and I want to remplace all missing value by 14.5 and 28, I mean like this

ID month mark   last
1   4        14.5    28
1   5        14.5    28
1   1        14.5    28
1   3        14.5    28
2   7        14.5    28

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

ok, with automatically, I take it that you mean that you always have the nonmissing value in the first observation? 🙂

 

So

 

data want;
	set mydata;
	if _N_ = 1 then do;
		temp_mark = mark;
		temp_last = last;
		retain temp_mark temp_last;
	end;
	if missing(mark) then mark=temp_mark;
	if missing(last) then last = temp_last;

	drop temp_mark temp_last;
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data mydata;
input id month mark last;
cards;
1 4 14.5 28
1 1 . .
1 3 . .
2 7 . .
;
run;

data want;
	set mydata;
	if missing(mark) then mark=14.5;
	if missing(last) then last = 28;
run;
John4
Obsidian | Level 7

Yes but since I have a large data set, I want to do it automatically

PeterClemmensen
Tourmaline | Level 20

ok, with automatically, I take it that you mean that you always have the nonmissing value in the first observation? 🙂

 

So

 

data want;
	set mydata;
	if _N_ = 1 then do;
		temp_mark = mark;
		temp_last = last;
		retain temp_mark temp_last;
	end;
	if missing(mark) then mark=temp_mark;
	if missing(last) then last = temp_last;

	drop temp_mark temp_last;
run;
John4
Obsidian | Level 7

Yes Smiley Happy

Ksharp
Super User
data mydata;
input id month mark last;
cards;
1 4 14.5 28
1 1 . .
1 3 . .
2 7 . .
;
run;

data want;
	set mydata(drop= mark last);
 if _n_=1 then set mydata(keep= mark last obs=1);
run;

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
  • 5 replies
  • 775 views
  • 2 likes
  • 3 in conversation