BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ChuksManuel
Pyrite | Level 9

Hello guys,

 

please view my output. I want to make my data-set to have only observations that responded yes (1) and No (2) based on COPD . And to delete the observations coded 7 and 9. Here's my code so far

 

LIBNAME perm 'D:\';
DATA Newsasdata (keep= Alchrc10 Alchrc9 cbrchyr chlev copdev ephev R_Maritl Age_p MracbpI2 sex hypev);
SET perm.nhis2012sampleadult;
RUN;

 

 

 

.COPD.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Are you looking for this

 

LIBNAME perm 'D:\';
DATA Newsasdata (keep= Alchrc10 Alchrc9 cbrchyr chlev copdev ephev R_Maritl Age_p MracbpI2 sex hypev);
SET perm.nhis2012sampleadult;
where copdev not in (7,9);
RUN;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Post the sample of your dataset plz

ChuksManuel
Pyrite | Level 9

I've posted the output and the code. I want to delete the observations that answered 7 and 9 from my entire dataset

novinosrin
Tourmaline | Level 20

Are you looking for this

 

LIBNAME perm 'D:\';
DATA Newsasdata (keep= Alchrc10 Alchrc9 cbrchyr chlev copdev ephev R_Maritl Age_p MracbpI2 sex hypev);
SET perm.nhis2012sampleadult;
where copdev not in (7,9);
RUN;

ballardw
Super User

@ChuksManuel wrote:

Hello guys,

 

please view my output. I want to make my data-set to have only observations that responded yes (1) and No (2) based on COPD . And to delete the observations coded 7 and 9. Here's my code so far

 

LIBNAME perm 'D:\';
DATA Newsasdata (keep= Alchrc10 Alchrc9 cbrchyr chlev copdev ephev R_Maritl Age_p MracbpI2 sex hypev);
SET perm.nhis2012sampleadult;
RUN;

 

 


You may want to consider creating a new recoded variable with code similar to :

data recode;
   set have;
   copd_recode = copd;
   if copd in (7,9) then call missing(copd_recode);
run;

And use the recoded variable.

 

One reason is suppose you also want to see frequencies of another variable. If you actually remove the records then the counts for the other variables would be affected. By creating another variable with missing then the proc freq (or other procedures) will have the correct number of observations to use with the other variables. If you do something like copd_recode*sex with the recoded variable then their will be indications of missing values but the counts and percentages within the categories would be represented.

 

And if that data comes from BRFSS then I have seen lots of recodes like that.

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 972 views
  • 0 likes
  • 3 in conversation