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

In the below example, 

 


data test;
input ID Name$;
datalines;
121 Kiran
768 Kumar
tyu Raj
;
run;

data good bad;
set test;
if _error_=1 then output bad;
else output good	;
run;

proc print data=bad;
run;

The dataset 'bad' is showing 0 observations, however i expect it to list the last observation from dataset, as there is a data error (_error_=1); Could some one please explain why it is not showing up.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You will want to read this:

https://v8doc.sas.com/sashtml/lrcon/z0695104.htm

 

Basically as the datastep runs its loop, it goes line by line into the PDV, _error_ is a variable in that PDV which does not get written to the output dataset.  So after the first run; that variable no longer exists.  It is created again in the second step, but as there are no errors then the _error_ variable is always false, hence no observations.  This will work as the if _error_ is in the same step:

data bad good;
  input ID Name$;
  if _error_ then output bad;
  else output good;
datalines;
121 Kiran
768 Kumar
tyu Raj
;
run;

 

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You will want to read this:

https://v8doc.sas.com/sashtml/lrcon/z0695104.htm

 

Basically as the datastep runs its loop, it goes line by line into the PDV, _error_ is a variable in that PDV which does not get written to the output dataset.  So after the first run; that variable no longer exists.  It is created again in the second step, but as there are no errors then the _error_ variable is always false, hence no observations.  This will work as the if _error_ is in the same step:

data bad good;
  input ID Name$;
  if _error_ then output bad;
  else output good;
datalines;
121 Kiran
768 Kumar
tyu Raj
;
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 865 views
  • 0 likes
  • 2 in conversation