Desktop productivity for business analysts and programmers

delete all the records with perticular id

Reply
Contributor brm
Contributor
Posts: 30

delete all the records with perticular id

Hi,

If One coloum is missing,then i want to delete all the records under that id.

How can i do this using query analyser in EG.Thanks in advance

brm
Respected Advisor
Posts: 3,831

Re: delete all the records with perticular id

Hi

Assuming you're talking about the Query Builder and that "deleting" means you don't want such observations in the output then one way to go could be (EG 4.2):

1. Tab "Select Data":
Define a computed column. Step 1: "advanced expression", step 2: select your variable with missings, step 3: under Summary choose "NMISS"

2. Tab "Select Data":
Have your ID variable under "Summary groups".

3. Tab "Filter": Add the calculated variable to "Filter the summarized data". In a "basic filter" set the condition to "Equals to" with value "0"


This should result in SQL code which looks like:

PROC SQL;
CREATE TABLE SASUSER.QUERY_FOR_HAVE AS
SELECT t1.id,
t1.var,
/* nmiss_var */
(NMISS(t1.var)) AS nmiss_var
FROM WORK.HAVE AS t1
GROUP BY t1.id
HAVING (CALCULATED nmiss_var) = 0;
QUIT;


HTH
Patrick
Contributor
Posts: 20

Re: delete all the records with perticular id

Patrick,

I did as you suggested...Here is the code generated

PROC SQL;
CREATE TABLE SASUSER.QUERY_FOR_BOOK13 AS
SELECT /* results */
(NMISS(t1.'Next Milestone Type'n)) AS results,
t1.DRC_CASE_ID,
t1.'Next Milestone Type'n
FROM SASUSER.BOOK13 AS t1
GROUP BY t1.DRC_CASE_ID
HAVING (CALCULATED results) = 0;
QUIT;

Getting below error in logs

ODS PDF(EGPDF) printed no output.
(This sometimes results from failing to place a RUN statement before the ODS PDF(EGPDF) CLOSE
statement.)

Please Tell me where i'm doing wrong.

Thanks,
reddy Message was edited by: reddy19
Respected Advisor
Posts: 3,831

Re: delete all the records with perticular id

Hi reddy

The generated code as such looks o.k. to me.

If you don't get an output then one reason could be that variable 'Next Milestone Type'n has missing values for every single distinct value of by group variable "DRC_CASE_ID".

I'm hardly using PDF output so can't say anything about this one.

First thing I would try is running the script with another output destination to see if it's an ODS PDF issue or something else.

HTH
Patrick
Contributor brm
Contributor
Posts: 30

Re: delete all the records with perticular id

Hi Patrick,

Below query is giving only the number of missing values

SELECT /* results */
(NMISS(t1.'Next Milestone Type'n)) AS results

So there is no way to exclude rows by id....because of that it is throwing error.

Thanks,
Bhavani.
Respected Advisor
Posts: 3,831

Re: delete all the records with perticular id

Hi brm

Of course you can exclude rows by ID. The code I've posted was tested and returned the expected result.

The important part is the "group by" ID and "having clause" selecting only ID's where NMISS returned 0 (=no missings).

What reddy19 doesn't get is an output - but that can be caused by having missings for every by group. We have to wait for reddy19's next posting to know more.
Ask a Question
Discussion stats
  • 5 replies
  • 198 views
  • 0 likes
  • 3 in conversation