DELETE statement executed, observation still written to dataset

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

DELETE statement executed, observation still written to dataset

The IF statement should be removing the current observation less than 2 from the dataset.  That is not happening

===============================================

===============================================

FILENAME XR '/folders/myfolders/Data.txt' LRECL=29;

DATA WORK;
INFILE XR MISSOVER;
INPUT XRPKLR @;

IF XRPKLR LT 2 THEN DELETE;
LENGTH
SEQN 7
XRPKLR 8
XRPKLL 8
XRPOMFR 8
XRPOMFL 8
XRPOMTR 8
XRPOMTL 8
XRPOLFR 8
XRPOLFL 8
XRPOLTR 8
XRPOLTL 8
XRPSMFR 8
XRPSMFL 8
XRPSMTR 8
XRPSMTL 8
XRPSLFR 8
XRPSLFL 8
XRPSLTR 8
XRPSLTL 8
XRPCHOR 8
XRPCHOL 8
XRPJRR 8
XRPJRL 8
;
FORMAT
;
INPUT
SEQN 1-5
XRPKLR 6
XRPKLL 7
XRPOMFR 8
XRPOMFL 9
XRPOMTR 10
XRPOMTL 11
XRPOLFR 12
XRPOLFL 13
XRPOLTR 14
XRPOLTL 15
XRPSMFR 16
XRPSMFL 17
XRPSMTR 18
XRPSMTL 19
XRPSLFR 20
XRPSLFL 21
XRPSLTR 22
XRPSLTL 23
XRPCHOR 24
XRPCHOL 25
XRPJRR 26
XRPJRL 27
;
LABEL
SEQN = "Respondent identification number"
XRPKLR = "Kellgren-Lawrence score, right knee"
XRPKLL = "Kellgren-Lawrence score, left knee"
XRPOMFR = "Osteophyte - medial femoral, right knee"
XRPOMFL = "Osteophyte - medial femoral, left knee"
XRPOMTR = "Osteophyte - medial tibial, right knee"
XRPOMTL = "Osteophyte - medial tibial, left knee"
XRPOLFR = "Osteophyte - lateral femoral, right knee"
XRPOLFL = "Osteophyte - lateral femoral, left knee"
XRPOLTR = "Osteophyte - lateral tibial, right knee"
XRPOLTL = "Osteophyte - lateral tibial, left knee"
XRPSMFR = "Sclerosis - medial femoral, right knee"
XRPSMFL = "Sclerosis - medial femoral, left knee"
XRPSMTR = "Sclerosis - medial tibial, right knee"
XRPSMTL = "Sclerosis - medial tibial, left knee"
XRPSLFR = "Sclerosis - lateral femoral, right knee"
XRPSLFL = "Sclerosis - lateral femoral, left knee"
XRPSLTR = "Sclerosis - lateral tibial, right knee"
XRPSLTL = "Sclerosis - lateral tibial, left knee"
XRPCHOR = "Chondrocalcinosis - right knee"
XRPCHOL = "Chondrocalcinosis - left knee"
XRPJRR = "Joint replacement - right knee"
XRPJRL = "Joint replacement - left knee"
;
RUN;
PROC PRINT DATA=WORK;
RUN;


Accepted Solutions
Solution
‎04-13-2016 06:38 PM
Esteemed Advisor
Posts: 5,010

Re: DELETE statement executed, observation still written to dataset

Perhaps the first INPUT statement should read:

 

input XRPKLR 6 @;

 

Otherwise, you're getting the value starting at column 1.

View solution in original post


All Replies
Grand Advisor
Posts: 17,474

Re: DELETE statement executed, observation still written to dataset

I think it's because you have a second input after the delete statement. 

 

If you want to conditionally input a line you need to change the logic to if VAR GE 2 then input the remaining records.

See a sample here under Full Code.

http://support.sas.com/kb/45/289.html

 

Or add the delete after your second input statement. 

 

It's an order of operations idea.

 

PS. Please only include the relevant code, log and output. It's hard to parse through that many pages to figure out what's going on.  

 

 

 

 

Occasional Contributor
Posts: 19

Re: DELETE statement executed, observation still written to dataset

Reeza. you have been so helpful to me. thank you but the correct solution was from user Astounding below. Until .....
Esteemed Advisor
Posts: 6,736

Re: DELETE statement executed, observation still written to dataset

Change

IF XRPKLR LT 2 THEN DELETE;

to

if xrpklr >= 2;

and try it out.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 19

Re: DELETE statement executed, observation still written to dataset

thanks for the effort. the user Astounding had the correct answer
Solution
‎04-13-2016 06:38 PM
Esteemed Advisor
Posts: 5,010

Re: DELETE statement executed, observation still written to dataset

Perhaps the first INPUT statement should read:

 

input XRPKLR 6 @;

 

Otherwise, you're getting the value starting at column 1.

Occasional Contributor
Posts: 19

Re: DELETE statement executed, observation still written to dataset

This worked. Excellent. I knew this was the answer when I read it.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 503 views
  • 1 like
  • 4 in conversation