Help using Base SAS procedures

Question About Recoding Variables

Reply
New Contributor
Posts: 2

Question About Recoding Variables

I am having trouble using a program from the NHANES continuous tutorial web site.  Essentially, I want to recode values of 7 and 9 as missing values "."  Here is the program:

Data demo_BP1;

set demo_BP;

If BPQ010 in (7,9) then BPQ010=.;

Data demo_BP1;

set demo_BP;

array _rdmiss BPQ020 BPQ070 BPQ080 MCQ160b--MCQ160f;

do over _rdmiss;

if _rdmiss in (7, 9) then _rdmiss=.;

end;

run;

The problem is that if I whichever one I run first will not recode the 9 as a "."  The one I run last will recode the 9.  Any suggestions?  Thank you so much for your help! (I'm not a syntax person, as you can tell, but I'm trying to learn!)

New SAS User,

Whitney

New Contributor
Posts: 2

Question About Recoding Variables

Never mind everyone - I just figured it out!  I thought it was a problem to define the new dataset twice!  I took that command out of the second set of instructions, and it worked.  CDC should explain this Smiley Happy

Super Contributor
Posts: 1,636

Re: Question About Recoding Variables

Yes, your code is fine.

data demo_bp;

input BPQ010 BPQ020 BPQ070 BPQ080;

cards;

7 9 8 6

8 10 11 12

9 12 9 19

;

proc print;

title from dataset &syslast;

run;

Data demo_BP1;

set demo_BP;

If BPQ010 in (7,9) then BPQ010=.;

run;

proc print;

title from dataset &syslast;

run;

Data demo_BP2;

set demo_BP;

array _rdmiss BPQ010 BPQ020 BPQ070 BPQ080 ;

do over _rdmiss;

if _rdmiss in (7, 9) then _rdmiss=.;

end;

proc print;

title from dataset &syslast;

run;

Linlin

PROC Star
Posts: 7,366

Question About Recoding Variables

Glad that you figured it out yourself.  Two things, though.  You didn't have a run statement after your first datastep, thus it wouldn't actually run until AFTER it started the second datastep.

Second, in the second datastep, you are trying to recode 7s and 9s but, for at least the first few of those variables, there aren't any 7s or 9s in the data.

Ask a Question
Discussion stats
  • 3 replies
  • 143 views
  • 0 likes
  • 3 in conversation