DATA Step, Macro, Functions and more

sas data

Reply
Occasional Contributor
Posts: 12

sas data

hi friends ,

any body clearify my doute ,

data set " A" have 100 observations(inputdataset), "B" output dataset,

 

in dataset " A" ,every 5th observation should come to data set "B" ,

 

let me clearify me?

Contributor
Posts: 41

Re: sas data

Posted in reply to ganeshsas764
One way to do this would be:

DATA B (DROP=count);
SET A;
RETAIN count 1;
IF count = 5 THEN DO;
OUTPUT;
count = 1;
END;
ELSE
count =count + 1;
RUN;
Contributor
Posts: 66

Re: sas data

Posted in reply to ganeshsas764

or more simply:

data b;

   set a;

   if mod(_n_,5) = 0 then output;

run;

Michelle
SAS Employee
Posts: 3

Re: sas data

Posted in reply to mbuchecker

The previous examples read every row then output every 5th.

Fine for a one-off run or a small sample.

This is more efficient technique which only reads every 5th row but it's slightly more code.

 

data b;

  do i = 1 to rows by 5;

  set a point=i nobs=rows;

  output;

  end;

stop;

run;

SAS Employee
Posts: 3

Re: sas data

Posted in reply to PeterHobart

One more option, if you have SAS/Stat.

this will generate a randon 20% sample

 

proc surveyselect data=a out=b
rate=0.2;
run;
quit;

Trusted Advisor
Posts: 1,118

Re: sas data

Posted in reply to PeterHobart

And if you have SAS/STAT 13.1 or higher, you can use PROC SURVEYSELECT also to literally select every 5th observation (without any random component):

proc surveyselect data=a out=b
method=sys(start=5) rate=0.2;
run;
Ask a Question
Discussion stats
  • 5 replies
  • 271 views
  • 0 likes
  • 5 in conversation