BookmarkSubscribeRSS Feed
corkee
Calcite | Level 5

Hi, I am using SAS to clean survey data. There are two versions of the survey (one in English and one in Spanish), and the goal here is to "convert" Spanish variables to English variables. I've written macros to assign the English variables the values of their Spanish counterparts. Everything works fine for numeric values, but I get this following message when dealing with character values: 

 

NOTE: Character values have been converted to numeric values

 

Is there any way to stop this automatic conversion and simply do "English var = Spanish var"? Thank you.

12 REPLIES 12
ballardw
Super User

It really helps to show at least some example data when requesting data manipulation tips. Show a few examples for some variables from each data set and what the result should be.

It appears that you have two data sets. You may need to check between the two if the variables are the same type (proc contents for example) as it appears you may have that issue from the message. If that is the case you should describe how the data was brought into SAS. Hint: Proc Import guesses as to varaible type and depending on the source file type (Excel is about the worst) and options the guesses may not be very good.

 

Also you should show the code that generated the message. You will get this if you do:  If Var = 9 then (do something) if Var is character. The fix would be If Var='9' then (do something).

corkee
Calcite | Level 5

Hi, ballardw. Thank you for the reply.

 

This is my macro:

 

%MACRO spantoengother(dataset=, numofvars=, firstvareng=, lastvareng=, firstvarspan=, lastvarspan=);
data &dataset;
	set &dataset;
	array areverseeng {&numofvars} &firstvareng--&lastvareng;
	array areversespan {&numofvars} &firstvarspan--&lastvarspan;
	do i=1 to dim(areversespan);
		if areversespan{i} ne . then areverseeng[i] = areversespan[i];
        end;
run;
%MEND spantoengother;

I know that variables in an array have to be the same type, so I made sure that the variables are the same type. For now, let's say I have a variable that contains an individual's email address (one for English and one for Spanish). I simply want to set email_eng to whatever is in email_span, if there isn't a missing value.

Reeza
Super User

For a character variable you need to have an array declared with $ in it, otherwise it defaults to numeric. 

 

And missing in character variables is " ". If you want the code to work for both numeric or character using MISSING() function instead.

 

	array areverseeng {&numofvars} $ &firstvareng--&lastvareng;
	array areversespan {&numofvars} $  &firstvarspan--&lastvarspan;
	do i=1 to dim(areversespan);
		if not missing(areversespan[i]) then areverseeng[i] = areversespan[i];
        end;
corkee
Calcite | Level 5
I will try that. Thank you!
corkee
Calcite | Level 5
Hi, Reeza. I tried this, but it did not work. I'm getting "999"'s instead of the email address. Weird.
Reeza
Super User

Are the 999s missing in the character variables? or are they coded in some other manner?

corkee
Calcite | Level 5
They're missing, but for one of the observations that I looked at, what was inputted for the Spanish variable was not transferred to its English counterpart. No idea why.
Reeza
Super User

With what you've posted I can't guess either 🙂

If you can't post actual data to replicate your issue you'll need to contact tech support.

corkee
Calcite | Level 5
Ugh, guess that's the only solution, as it contains personal identifying information. Thanks anyway! 🙂
corkee
Calcite | Level 5
Hmm...it seems to not work for only ONE of the observations, as it works for the others...
Reeza
Super User

Then there's something specific about that observation.

You should be able to strip the identifying information and replicate the error.

 

Filter out that specific obs. Then check if it passes the missing criteria or not.

ballardw
Super User

Are you seeing any messages in the log about encoding such a UTF-8 and WLATIN or other strangeness.

Other option is that some of the data may actually be UNICODE characters. They might look like "999" but are actually represented by different characters that are different than the ones you enter in the editor.

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
  • 12 replies
  • 2628 views
  • 0 likes
  • 3 in conversation