Hallo to everyone,
Could someone help me with this?
I have one really big data set ,and from this I wanna to create one new .After the where statement I keep only the observation that are really needed. The problem is ,i want this observations and their exactly next.For example if from the where statement I keep the observations 1 ,100,and 1000 in the new data set i will have the observations 1,2(1+1),100,101(100+1),1000,1001(1000+1).
Thanks in advance,
Barney
I don't think a WHERE statement is going to work (assuming the following observation doesn't meet your where clause)
Here's a simple example of how you can do it using an IF statement
data have ;
do i=1 to 10 ;
j=mod(i,3) ;
output ;
end ;
run ;
data want ;
retain flag 0 ;
set have ;
if j=0 then do ;
output ;
flag=1 ;
end ;
else if flag=1 then do ;
flag=0 ;
output ;
end ;
run ;
This sounds odd enough that I think you need to provide some example data and the expected results. It does not need to be 1000's or records long but enough to see what is needed.
For example, how do you write your where statement to select 1, 100 and 1000?. You should show the basic code you are currently using to select those records. The entire step.
I suspect that a solution will require more than one step as a Where that selects records will not select any records that do not meet the condition. So if record 100 meets your where condition and 99 does not then the record 99 is not available at that time.
Do you really know the observation numbers you want (1, 100, 1000 and their successors)?
If obs num is the guiding criterion, then the WHERE statement will not produce what you want. because observation numbers are generated AFTER the where filter, not before.
But in this situation you can use SET with the POINT= option.
%let obslist=1,100,1000;
data want;
do ptr=&obslist;
set have point=ptr;
output;
ptr=ptr+1;
set have point=ptr;
output;
end;
stop;
run;
And even if the where filter would be based on some desired variable value, the where filter will not provide the observation following the desired value. You'll have to use subsetting IF and the LAG function.
data want;
set sashelp.class;
if age=15 or lag(age)=15;
run;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.
Ready to level-up your skills? Choose your own adventure.