Hi,
I am dealing with an error that produces 0 observations in my newly formed data set once I use "then delete" statement for missing data or if I want to delete unusual values. Why would that be? I pasted the code below.
Thanks!
data NHANES05.cycle_full;
set NHANES05.NHANES_0506_full_b;
/*Poverty Income Ratio*/
if INDFMPIR<=0.99 then poorcat1=1; else poorcat1=0;
if INDFMPIR>1 and INDFMPIR<=1.99 then poorcat2=1; else poorcat2=0;
if INDFMPIR>2 and INDFMPIR<=2.99 then poorcat3=1; else poorcat3=0;
if INDFMPIR>3 and INDFMPIR<=3.99 then poorcat4=1; else poorcat4=0;
if INDFMPIR>4 and INDFMPIR<=4.99 then poorcat5=1; else poorcat5=0;
if INDFMPIR>5 then poorcat6=1; else poorcat6=0;
if INDFMPIR=. then poorcat=.;
run;
**delete missing data;
data NHANES05.cycle_full_a;
set NHANES05.cycle_full;
/*Poverty Income Ratio*/
if INDFMPIR>=0 and INDFMPIR<=5 then poor1=1; else poor1=0;
if INDFMPIR=. then delete; *none based on this code but outside of the 0-5, N=72 coded as missing;
run;
A few things, when you do "<=0.99" that is different than later when you specify ">=0". Also, I think you may have observations that are exactly equal to 1,2,3,4,5 but your bucketing does not capture them.
Given that I think you are trying to bucket the observations, I would use proc format instead. (if you don't want to include 1, 2, 3, etc. change 1-1.99 to 1<-1.99, 2-2.99 to 2<-2.99 etc.)
proc format;
value poorcat low-0.99=1 1-1.99=2 2-2.99=3 3-3.99=4 4-4.99=5 5-5.99=6 other=0;
run;
data have;
set sashelp.syr1001(keep=S0666);
poor_cat=put(S0666, poorcat.);
run;
data want;
set have;
if poor_cat ne 0;
run;
-unison
What does the log of both steps say? Please post it, using the {i} button.
Also inspect the contents of INDFMPIR in your initial dataset.
@maciulei wrote:
I checked the log and one of the imported files gave the error that the file is sequential in red. I fixed the issue by checking the file location, which was wrong. Now everything works!
That's why Maxim 2 is so high up on the list.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.