Write and run SAS programs in your web browser

how to limit observations and delete rows using one statement?

Reply
Occasional Contributor
Posts: 8

how to limit observations and delete rows using one statement?

I am using University Edition, and tried to limit observations in line 78.

I just want to have the output which only contains the "self" in variable V103.

and also want to drop rows, do I have to write down each row name, or is there any convenience way.

 

here is my log file.

 

 

 

 

61 proc import out=dataset3
 
62 datafile= '/folders/myfolders/Project/09836-0003-Data.'
63 dbms=sav
64 replace;
65
 
NOTE: The import data set has 31827 observations and 89 variables.
NOTE: WORK.DATASET3 data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.36 seconds
cpu time 0.24 seconds
 
66 data dataset3;
 
67 set dataset3;
68 NEWUCODE=input(UCODE,best32.);
69 drop UCODE;
70 rename NEWUCODE=UCODE;
71
 
NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
68:16
NOTE: There were 31827 observations read from the data set WORK.DATASET3.
NOTE: The data set WORK.DATASET3 has 31827 observations and 89 variables.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.09 seconds
 
72 data dataset3;
 
73 retain UCODE V103 V104;
74 set dataset3;
75
 
NOTE: There were 31827 observations read from the data set WORK.DATASET3.
NOTE: The data set WORK.DATASET3 has 31827 observations and 89 variables.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.08 seconds
 
76 data dataset3;
 
77 set dataset3;
78 if V103 ne self then delete;
79
 
NOTE: Variable self is uninitialized.
NOTE: There were 31827 observations read from the data set WORK.DATASET3.
NOTE: The data set WORK.DATASET3 has 68 observations and 90 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
cpu time 0.04 seconds
 
80 data dataset3;
 
81 drop V108 V116 V117 V201 V202 V203 V207 V210 V211 V212 V216 V217 V218 V221 V221A;
82 set dataset3;
83
84
 
NOTE: There were 68 observations read from the data set WORK.DATASET3.
NOTE: The data set WORK.DATASET3 has 68 observations and 75 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.02 seconds
 
85 proc means;
 
86 run;
 
NOTE: There were 68 observations read from the data set WORK.DATASET3.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.30 seconds
cpu time 0.30 seconds
Esteemed Advisor
Posts: 6,002

Re: how to limit observations and delete rows using one statement?

Without quotes, SAS assumes that self is the name of a variable. Character literals must be enclosed in single or double quotes.

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

Re: how to limit observations and delete rows using one statement?

i was tried to add the quotes, but there is another error that is:

 

ERROR: Variable V103 has been defined as both character and numeric.
Esteemed Advisor
Posts: 6,002

Re: how to limit observations and delete rows using one statement?


xiaolufan wrote:

i was tried to add the quotes, but there is another error that is:

 

ERROR: Variable V103 has been defined as both character and numeric.

Look at your data. If V103 is numeric, it makes no sense comparing it to the string "self".

Use proc contents on the input dataset(s).

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

Re: how to limit observations and delete rows using one statement?

You can just replace line 78 with this:

 

if V103='Self';

 

 

Occasional Contributor
Posts: 8

Re: how to limit observations and delete rows using one statement?

it still shows that ERROR: Variable V103 has been defined as both character and numeric.
Occasional Contributor
Posts: 8

Re: how to limit observations and delete rows using one statement?

Try using the put() function to transform V103 into a string variable. I find a solution to that error in the following URL:

 

https://communities.sas.com/t5/Base-SAS-Programming/Variable-has-been-defined-as-both-character-and-...

Post a Question
Discussion Stats
  • 6 replies
  • 223 views
  • 0 likes
  • 3 in conversation