BookmarkSubscribeRSS Feed
rfarmenta
Obsidian | Level 7

I had an intern help me recode other responses on a questionnaire. We had to recode them because several interviewers were typing in responses into the other field that could have fit into a category. The intern placed several other responses into categories but now I need to delete them out of the other field since they are now recategorized. For instance:

if DGOTH3A2="DRANK" then DG6FQ3AG=1;
else if DGOTH3A2= "DRANK IT" then DG6FQ3AG=1;
else if DGOTH3A2= "DRINK" then DG6FQ3AG=1;
else if DGOTH3A2= "DRINK IT" then DG6FQ3AG=1;
else if DGOTH3A2= "DRINKING IT" then DG6FQ3AG=1;
else if DG6FQ3AA>. then DG6FQ3AG=0;

She did not include code to say, to delete the "DRANK", for instance, from the other field variable DGOTH3A2, is there a way to do that short of me writing code that says:

if DGOTH3A2="DRANK" then delete.

We have lots of these we had to do this for so any help would be greatly appreciated.

4 REPLIES 4
Reeza
Super User

I'm assuming its not safe to the do the inverse?

ie if DG6GFQ3AG=1 then DGOTH3A2="";

You could modify the code to something as follows:

if DGOTH3A2 in ("DRANK", "DRANK IT", "DRINK", "DRINK IT",  "DRINKING IT") then do;

      DG6FQ3AG=1;

    DGOTH3A2 = "";

end;

else if DG6FQ3AA>. then DG6FQ3AG=0;

Generally, not something I recommend anyways. You shouldn't change source data, but assuming there's a good reason that's one way.

rfarmenta
Obsidian | Level 7

With the other options, there are more responses than just those listed, so if I have the code DGOTH3A2 = "";, will that clear out all of the responses and not just those listed?

I agree with not changing the source data but in this case, the first option for the question was "I drank it", so the other response can safely be re categorized there to have less missing data. We are also creating new variables based on the other responses for analysis purposes. Thanks for you help.

Tom
Super User Tom
Super User

It depends on whether they recoded when only part of the other response matched one of the categories.

For example if other='ATE AND DRANK' and they coded DRANK=1 would you want to convert other to just 'ATE'?

Try doing a proc freq to the the list of actual values.

proc freq ;

tables DGOTH3A2* DG6FQ3AG / missing;

run;

Are there other variables that they code from the other field besides just DRANK?  Perhaps you want to look at all of them?

Or perhaps you just want to clear the other variable when any of them is set?

if 0 < max(of DG6FQ3AG <other coded variables>) then DGOTH3A2;

rfarmenta
Obsidian | Level 7

You last statement is exactly what I want to do, clear the other variable when the option is used/re-categorized.

If the other had more than 1, then it would not be re-categorized into the variable because these are all select one variables.  Will try some of the code and see what I can come up with.

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