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
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
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
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: