Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign value to blank variable 2

Status
Not open for further replies.

Starbury

Programmer
Sep 11, 2007
6
US
I have a file with about 20,000 observations, but the variable A is blank in the vast majority of observations. All other variables have values for every observation.

The first observation provides a value for the variable A. I want to assign all successive observations with blank values the value for variable A.

The unduplicated value of variable A changes from beginning to end of observations.

I am trying to write a loop of some sorts that assigns the non-blank value of variable A to all successive blank values and then increment to the next unduplicated value of variable A for the next group of successive blanks.

Is this possible?
 
Starbury, not entirely sure if I've picked you up correctly here so I've put together an example bit of code for you, run it and let me know if this is what your looking for!

Code:
data InputFile;
input A $1. B;
datalines;
A 123
  456
  789
B 101
  102
  103
  104
C 987
  654
  321
;
run;

data Outputfile;
	set InputFile;
	retain HoldVar;

	if _n_=1 then do;
		HoldVar = A;
	end;
	else if A ne '' then do;

				HoldVar = A;
			end;

	Drop A;
	rename HoldVar = A;
	label HoldVar = A;
run;

Cheers

Nick
 
You are ridiculously talented genius. This worked perfectly! Many thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top