BookmarkSubscribeRSS Feed
WEB1975
Calcite | Level 5

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

3 REPLIES 3
WEB1975
Calcite | Level 5

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

Linlin
Lapis Lazuli | Level 10

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

art297
Opal | Level 21

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1018 views
  • 0 likes
  • 3 in conversation