Hello:
I would like to assign "All' in the blank cell for different variables (race, age, sex, risk)? I wrote the code below, however it didn't work. Any idea how?
Thanks.
%let X=RISK;
%let X=AGE;
%let X=SEX;
%let X=RACE;
data A;
SET B;
If &X=" " then &X="All";
run;
I'm guessing that this may be what you want:
data a;
set b;
array x Risk Age Sex Race;
/* since you attempting to assign a value of "All" I have to assume the above variables are all character*/
do i = 1 to dim(r);
If missing(r[i]) then r[i] = 'All';
end;
drop i;
run;
But if this a data set to export and look like a report then I suggest it is often better to just use a report procedure.
If you have summary rows in data then you are asking for confusion is someone else uses the data set. Or if you have it around long enough to forget the summary.
Check what your code will resolve to:
data A;
SET B;
If RACE=" " then RACE="All";
run;
I'm guessing that's not what you want?
Not to sound like a broken record, but you probably don't need a macro here either.
Post what your data looks like and what you're trying to achieve.
I'm guessing that this may be what you want:
data a;
set b;
array x Risk Age Sex Race;
/* since you attempting to assign a value of "All" I have to assume the above variables are all character*/
do i = 1 to dim(r);
If missing(r[i]) then r[i] = 'All';
end;
drop i;
run;
But if this a data set to export and look like a report then I suggest it is often better to just use a report procedure.
If you have summary rows in data then you are asking for confusion is someone else uses the data set. Or if you have it around long enough to forget the summary.
Thanks for the great suggestion, it works! 🙂
You may also want to back up a step - depending on how you're calculating things you may be able to avoid the missing in the first place.
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.