BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

5 REPLIES 5
Reeza
Super User

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.

 

 

ballardw
Super User

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.

ybz12003
Rhodochrosite | Level 12

Thanks for the great suggestion, it works! 🙂

LinusH
Tourmaline | Level 20
Or use formats, that wouldn't require any data updates.
Data never sleeps
Reeza
Super User

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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