DATA Step, Macro, Functions and more

How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

Accepted Solution Solved
Reply
Super Contributor
Posts: 319
Accepted Solution

How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

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;

 


Accepted Solutions
Solution
‎03-29-2016 12:40 PM
Super User
Posts: 11,336

Re: How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

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.

View solution in original post


All Replies
Super User
Posts: 19,768

Re: How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

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.

 

 

Solution
‎03-29-2016 12:40 PM
Super User
Posts: 11,336

Re: How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

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.

Super Contributor
Posts: 319

Re: How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

Thanks for the great suggestion, it works! Smiley Happy

Super User
Posts: 5,424

Re: How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

Or use formats, that wouldn't require any data updates.
Data never sleeps
Super User
Posts: 19,768

Re: How to assign "All' in the blank cell for different variables (race, age, sex, risk)?

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 244 views
  • 7 likes
  • 4 in conversation