I'm very new to Macro. I have 5 variables A,B,C,D,E. also I have a code need to repeat, this code used for filling up previous missing value.
data want;
do until(not missing(status) or last.id );
set have;
by id;
end;
temp=status;
do until(not missing(status) or last.id );
set have;
by id;
_status=temp;output;
end;
drop temp status;
run;
I need input variable A into this code, then generate table A, then use tableA as base table, then input variableB into tableA, and so on, until I input last variable E. So final table E will come out, which contains all 5 variables with filling values.
My logic to get what I want:
data tableA;
set old;
(fill up variableA);
run;
data tableB;
set tableA;
(same fill up code to fill up tableB);
run;
.....
data tableE;----------FINAL table filling up all missing values for 5 variables.
set tableD;
(same fill up code tp input variableE);
run;
sample data have:
id varA B C D E
1 . . . . .
1 n m l p k
want:
id varA B C D E
1 n m l p k
1 n m l p k
I know how to fill up one by one. I'm thinking if I can use macro to get this final table? or other ways to do that? Thank you for your help! Appreciate!
There are numerous ways of doing it, for example:
data have; infile datalines dlm="," dsd; input id vara $ varb $ varc $ vard $ vare $; datalines; 1,,,,, 1,n,m,l,p,k ; run; data want; update have have (where=(vara ne "")); by id; run;
Or:
data want; set have (where=(vara ne "")) have (where=(vara ne ""); run;
But i dont think its that straight forward, I can only go on your test data however. Please post test data in the form of a datastep as I have done above in future.
There are numerous ways of doing it, for example:
data have; infile datalines dlm="," dsd; input id vara $ varb $ varc $ vard $ vare $; datalines; 1,,,,, 1,n,m,l,p,k ; run; data want; update have have (where=(vara ne "")); by id; run;
Or:
data want; set have (where=(vara ne "")) have (where=(vara ne ""); run;
But i dont think its that straight forward, I can only go on your test data however. Please post test data in the form of a datastep as I have done above in future.
You can do it all in one easy step, somewhat similar to the @RW9 suggestion:
data want;
update have (obs=0) have;
by id;
output;
run;
Note that this will affect all variables, not just the five of interest.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.