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

I currently have a race variable categorized as Asian, Black or Africian-American, Native Hawaiian or Pacific Islander, Other or White.  I would like to change the Asian and Native Hawaiian or Pacific Islander to Other using the same race variable name.  I did not create the dataset.  I am doing secondary data analysis.  I am using SAS 9.4.

 

I tried the following code, but it did not work and did not give me an error message.  Do I have to create a new variable for race or can I use the same variable name?

if strip(race)="Native Hawaiian or Pacific Islander" OR strip(race)="Asian" then race="Other";

 

Any help that could be provided would be appreciated.

 

Thanks,

Paula

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Well, you didn't tell us what the error message actually is.  So here's my guess.

 

I guess that your RACE variable is actually numeric.  The strings that you are looking at like "Asian" are actually formatted values.  So you can't apply STRIP to a numeric variable.  Here's how you would confirm this:

 

proc print data=have (obs=20);

var race;

run;

 

proc print data=have (obs=20);

var race;

format race;

run;

 

The FORMAT statement (with no format named) will remove any existing format from the variable, for the purposes of running the second PROC PRINT.  Then you can see whether the actual values are different than the displayed values.

 

View solution in original post

7 REPLIES 7
Reeza
Super User

The concept is correct. 

You do have to make sure it's exactly matching the string, case et al.

Is it Native Hawaiian or Pacific Islander in one field or are those separate? I also find IN easier to work with.

 

 

if strip(race) in ("Native Hawaiian or Pacific Islander", "Asian")  then race="Other";
PaulaC
Fluorite | Level 6
I just checked and it is all in one field.
Astounding
PROC Star

Well, you didn't tell us what the error message actually is.  So here's my guess.

 

I guess that your RACE variable is actually numeric.  The strings that you are looking at like "Asian" are actually formatted values.  So you can't apply STRIP to a numeric variable.  Here's how you would confirm this:

 

proc print data=have (obs=20);

var race;

run;

 

proc print data=have (obs=20);

var race;

format race;

run;

 

The FORMAT statement (with no format named) will remove any existing format from the variable, for the purposes of running the second PROC PRINT.  Then you can see whether the actual values are different than the displayed values.

 

PaulaC
Fluorite | Level 6

Thank you for your message. I did not receive an error message which is the reason I could not figure out why it did not work.

I will try your suggestion to see if the actual variable is numeric or categorical.

 

Thanks.

Astounding
PROC Star

Sorry, I misread the part in the original post about the error message.  But the next steps wouldn't change ... run the test PROC PRINTs, and it might also help to post the log from the original program.

ballardw
Super User

Personally I would recommend either developing a custom format to change displayed values without changing the variable OR create an entire new variable.

 

I would bet a small pile of quarters that some time in the future you get asked to report on one or both of Asian or NHOPI. Which will be much easier if the values still exist.

PaulaC
Fluorite | Level 6
ok. Thanks for your suggestion and response.

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
  • 7 replies
  • 2350 views
  • 2 likes
  • 4 in conversation