03-27-2012 07:54 AM
data l; infile cards missover truncover; input add $ 1-100; cards; q w e r t y r t t t qwerret w a d f g g run; data l2; set l; if (SCAN(add,5,' ') EQ '' | LENGTH(COMPRESS(add, ' ') ) <10 | LENGTH(COMPRESS(add, ' ')) >200) then do; add_QC1 =''; add_QC2 =''; add_QC3 = ''; end; else do; add_QC1 = add ; add_QC2 = ''; add_QC3 = '' ; end; run; Actually i am checking if it is having 5 words and length <10 and length greate than 200 i want the output to be : obs add add_QC1 --- --- 1. q w e r t y q w e r t y 2. r t t t 3. qwerret w a d f g g qwerret w a d f g g
03-27-2012 09:18 AM
There are several features of your program to either correct or clarify.
First, do not use both TRUNCOVER and MISSOVER. Pick one or the other. My choice would be neither, but to use:
infile cards lrecl=100 pad;
Since you want to read 100 characters from the data lines, make sure you have 100 characters to read.
Second, you say you want three conditions to be met, using AND to join the three conditions. But the code uses | which means OR. I suspect you actually mean OR, since it is not possible for the length to be both less than 10 and greater than 200. But perhaps it is some combination of AND and OR. You need to clarify the conditions you want to meet.
Third, since your program reads 100 characters as the value for ADD, it is not possible for the length to be greater than 200.
Finally, the statement add_QC1=''; defines add_QC1 as being 1 character long. If the later statement executes (add_QC1 = add, there is not enough room to store the full value of ADD. Instead, it will be truncated down to a single character. The easiest solution is to add a LENGTH statement toward the beginning of the DATA step, defining ADD_QC1 as being 100 characters long.
Patch up this much, and we'll see if the questions remain.
03-27-2012 10:20 AM
That statement is checking that ADD contains fewer than 5 words (using blanks as delimiters). The SCAN function returns a blank when it searches for a fifth word and doesn't find one. A few more variations ...
To find ADD with at least 5 words:
if SCAN(add, 5, ' ') > ' ' then ...
To find ADD with exactly 5 words:
if SCAN(add, 5, ' ') > ' ' and scan(add, 6, ' ') = ' ' then ...
Hope this helps.
03-28-2012 02:26 AM
if it is having 5 words and length <10 and length greate than 200
Actually,I do not understand what you mean.
Since you want length<10 ,why do you need > 200 ?
data l; infile cards truncover; input add $ 1-100; cards; q w e r t y r t t t t qwerret w a d f g g run; data l2; set l; length add_QC1 $ 100; if countw(add) eq 5 and LENGTH(COMPRESS(add, ' ') ) <10 or LENGTH(COMPRESS(add, ' ')) >200 then add_QC1=' '; else add_QC1=add; run;