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.
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.
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.